add
This commit is contained in:
19
ccxt/test/base/language_specific/test_language_specific.py
Normal file
19
ccxt/test/base/language_specific/test_language_specific.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
from ccxt.test.base.test_deep_extend import test_deep_extend # noqa E402
|
||||
|
||||
def test_language_specific():
|
||||
pass
|
||||
114
ccxt/test/base/test_after_constructor.py
Normal file
114
ccxt/test/base/test_after_constructor.py
Normal file
@@ -0,0 +1,114 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
def helper_test_init_throttler():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
'rateLimit': 10.8,
|
||||
})
|
||||
# todo: assert (exchange.MAX_VALUE !== undefined);
|
||||
token_bucket = exchange.get_property(exchange, 'tokenBucket') # trick for uncamelcase transpilation
|
||||
if token_bucket is None:
|
||||
token_bucket = exchange.get_property(exchange, 'TokenBucket')
|
||||
assert token_bucket is not None
|
||||
assert 'GO_SKIP_START'
|
||||
rate_limit = exchange.get_property(exchange, 'rateLimit')
|
||||
assert rate_limit == 10.8
|
||||
assert token_bucket['delay'] == 0.001
|
||||
assert token_bucket['refillRate'] == 1 / rate_limit
|
||||
assert 'GO_SKIP_END'
|
||||
# fix decimal/integer issues across langs
|
||||
assert exchange.in_array(token_bucket['capacity'], [1, 1])
|
||||
cost = exchange.parse_to_numeric(exchange.safe_string_2(token_bucket, 'cost', 'defaultCost')) # python sync, todo fix
|
||||
assert exchange.in_array(cost, [1, 1])
|
||||
assert not ('maxCapacity' in token_bucket) or exchange.in_array(token_bucket['maxCapacity'], [1000, 1000])
|
||||
|
||||
|
||||
def helper_test_sandbox_state(exchange, should_be_enabled=True):
|
||||
assert exchange.urls is not None
|
||||
assert 'test' in exchange.urls
|
||||
assert 'GO_SKIP_START'
|
||||
is_sandbox_mode_enabled = exchange.get_property(exchange, 'isSandboxModeEnabled')
|
||||
if should_be_enabled:
|
||||
assert is_sandbox_mode_enabled
|
||||
assert exchange.urls['api']['public'] == 'https://example.org'
|
||||
assert exchange.urls['apiBackup']['public'] == 'https://example.com'
|
||||
else:
|
||||
assert not is_sandbox_mode_enabled
|
||||
assert exchange.urls['api']['public'] == 'https://example.com'
|
||||
assert exchange.urls['test']['public'] == 'https://example.org'
|
||||
assert 'GO_SKIP_END'
|
||||
|
||||
|
||||
def helper_test_init_sandbox():
|
||||
# todo: sandbox for real exchanges
|
||||
opts = {
|
||||
'id': 'sampleexchange',
|
||||
'options': {
|
||||
'sandbox': False,
|
||||
},
|
||||
'urls': {
|
||||
'api': {
|
||||
'public': 'https://example.com',
|
||||
},
|
||||
'test': {
|
||||
'public': 'https://example.org',
|
||||
},
|
||||
},
|
||||
}
|
||||
#
|
||||
# CASE A: when sandbox is not enabled
|
||||
#
|
||||
exchange3 = ccxt.Exchange(opts)
|
||||
helper_test_sandbox_state(exchange3, False)
|
||||
exchange3.set_sandbox_mode(True)
|
||||
helper_test_sandbox_state(exchange3, True)
|
||||
#
|
||||
# CASE B: when sandbox is enabled
|
||||
#
|
||||
opts['options']['sandbox'] = True
|
||||
exchange4 = ccxt.Exchange(opts)
|
||||
helper_test_sandbox_state(exchange4, True)
|
||||
exchange4.set_sandbox_mode(False)
|
||||
helper_test_sandbox_state(exchange4, False)
|
||||
|
||||
|
||||
def helper_test_init_market():
|
||||
# ############# markets ############# #
|
||||
sample_market = {
|
||||
'id': 'BtcUsd',
|
||||
'symbol': 'BTC/USD',
|
||||
'base': 'BTC',
|
||||
'quote': 'USD',
|
||||
'baseId': 'Btc',
|
||||
'quoteId': 'Usd',
|
||||
'type': 'spot',
|
||||
'spot': True,
|
||||
}
|
||||
exchange2 = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
'markets': {
|
||||
'BTC/USD': sample_market,
|
||||
},
|
||||
})
|
||||
assert exchange2.markets['BTC/USD'] is not None
|
||||
|
||||
|
||||
def test_after_constructor():
|
||||
helper_test_init_throttler()
|
||||
helper_test_init_sandbox()
|
||||
helper_test_init_market()
|
||||
22
ccxt/test/base/test_arrays_concat.py
Normal file
22
ccxt/test/base/test_arrays_concat.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
def test_arrays_concat():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
})
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'testArraysConcat', exchange.arrays_concat([['b'], ['a', 'c']]), ['b', 'a', 'c'])
|
||||
136
ccxt/test/base/test_cryptography.py
Normal file
136
ccxt/test/base/test_cryptography.py
Normal file
@@ -0,0 +1,136 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
import ccxt # noqa: F402
|
||||
import hashlib # noqa: F402
|
||||
|
||||
Exchange = ccxt.Exchange
|
||||
hash = Exchange.hash
|
||||
hmac = Exchange.hmac
|
||||
ecdsa = Exchange.ecdsa
|
||||
eddsa = Exchange.eddsa
|
||||
safe_string = Exchange.safe_string
|
||||
safe_integer = Exchange.safe_integer
|
||||
in_array = Exchange.in_array
|
||||
jwt = Exchange.jwt
|
||||
crc32 = Exchange.crc32
|
||||
rsa = Exchange.rsa
|
||||
encode = Exchange.encode
|
||||
|
||||
|
||||
def equals(a, b):
|
||||
return a == b
|
||||
|
||||
|
||||
# even though no AUTO_TRANSP flag here, self file is manually transpiled
|
||||
|
||||
|
||||
def test_cryptography():
|
||||
|
||||
# exchange = Exchange()
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
assert hash(encode(''), 'sha256', 'hex') == 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
||||
assert hash(encode('cheese'), 'sha256', 'hex') == '873ac9ffea4dd04fa719e8920cd6938f0c23cd678af330939cff53c3d2855f34'
|
||||
|
||||
assert hash(encode(''), 'md5', 'hex') == 'd41d8cd98f00b204e9800998ecf8427e'
|
||||
assert hash(encode('sexyfish'), 'md5', 'hex') == 'c8a35464aa9d5683585786f44d5889f8'
|
||||
|
||||
assert hash(encode(''), 'sha1', 'hex') == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
|
||||
assert hash(encode('nutella'), 'sha1', 'hex') == 'b3d60a34b744159793c483b067c56d8affc5111a'
|
||||
assert hmac(encode('hello'), encode('there'), hashlib.sha256, 'hex') == '551e1c1ecbce0fe9b643745a376584a6289f5f43a46861b315fac9edc8d52a26'
|
||||
assert hmac(encode('a message'), encode('a secret'), hashlib.md5, 'hex') == '0bfa503bdbc7358185fcd49b4869e23d'
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
privateKey = '1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a'
|
||||
|
||||
|
||||
assert(equals(ecdsa('1a', privateKey, 'secp256k1', 'sha256'), {
|
||||
'r': '23dcb2a2a3728a35eb1a35cc01743c4609550d9cceaf2083550f13a9eb135f9f',
|
||||
's': '317963fcac18e4ec9f7921b97d7ea0c82a873dd6299cbfb6af016e08ef5ed667',
|
||||
'v': 0,
|
||||
}))
|
||||
|
||||
|
||||
assert(equals(ecdsa(privateKey, privateKey, 'secp256k1', None), {
|
||||
'r': 'b84a36a6fbabd5277ede578448b93d48e70b38efb5b15b1d4e2a298accf938b1',
|
||||
's': '66ebfb8221cda925526e699a59cd221bb4cc84bdc563024b1802c4d9e1d8bbe9',
|
||||
'v': 1,
|
||||
}))
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#
|
||||
# assert exchange.hashMessage(privateKey) == '0x59ea5d98c3500c3729f95cf98aa91663f498518cc401360df2912742c232207f'
|
||||
#
|
||||
# assert(equals(exchange.signHash('0x59ea5d98c3500c3729f95cf98aa91663f498518cc401360df2912742c232207f', privateKey), {
|
||||
# 'r': '0x6f684aa41c02da83dac3039d8805ddbe79a03b1297e247c7742cab8dfc19d341',
|
||||
# 's': '0x62473881674550563cb028ff40a7846fd53620ddf40a20cc1003b8484a109a4a',
|
||||
# 'v': 27
|
||||
# }))
|
||||
#
|
||||
# assert(equals(exchange.signMessage(privateKey, privateKey), {
|
||||
# 'r': '0x6f684aa41c02da83dac3039d8805ddbe79a03b1297e247c7742cab8dfc19d341',
|
||||
# 's': '0x62473881674550563cb028ff40a7846fd53620ddf40a20cc1003b8484a109a4a',
|
||||
# 'v': 27
|
||||
# }))
|
||||
#
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
pemKeyArray = [
|
||||
'-----BEGIN RSA PRIVATE KEY-----',
|
||||
'MIIEpAIBAAKCAQEAqUtXQXv2uSm9zPvdJTRpu5/65rBjAoHmIiowAs+u7fY0QP9O',
|
||||
'+T8CZRQjvZrfPomBiccjCxDo8mm7GkmL67rs9s7VOMQFvpTTtMBeglNSEbXJ3wTt',
|
||||
'7WM5gD3ZAbhfGtwWdGpcOMX0hV5/d/fiw1zQk0+AooayTryZ7HV+DQcD1sGTYYir',
|
||||
'LePUGkKV2NCvKtGOQfRAtuo0ccigMxMvEhWuExCc9Fhd077OpXMc0n7OiFqA2JWN',
|
||||
'jlocM9S71Srvw/lDos8a7lGaFUV8gP1CsQY/4qTju6hhsRd4lFujVr5J9FqmDbnv',
|
||||
'wQ79SSu6+lT0+ToFdDHiYOorBK2ESFR7EzlyLwIDAQABAoIBAEobQMbZjNbg/sSM',
|
||||
'O/HdT6tiDGKPM8gVNLgf34RbhSeFbrpFCDzy6Al3F24YLUEi0CGPmjdt34q93blU',
|
||||
'GHvIB5LCV3PR2vHiFAo7ayOBdZtrCEMn1T7lAHaynBu0qW0IiovLQzNW9AKtqv7I',
|
||||
'8+qw5lyVoKmEbOkqhfaMN/Fb8MJAo3yEVyhyp4EjtFhqDQ9DuHEjp1jGthnMgm+4',
|
||||
'qFyELf0DXZSAN+R9IGDqWPyo78lOcPW4pgeLuoLQ6Nn/2JAEGHFt1a7zMEw5yYbR',
|
||||
'XB89Bh0dheSmopBN6Heay4YuhnNKua37OlL1/nhKpLGUNE3z/UOXeiUiMeE1C2i+',
|
||||
'GjK+xgECgYEA4XH63rJ3VYDHHWUGlWffFWkEpgR4BDEkZ8MyVYQoUjQA2TpCvQ2+',
|
||||
'bR7aAIGXhBnRTrIBNu9m4+am0aUfi1hVmVHqt1b2vFgEb9uKuO4U62tCFpeji+Rz',
|
||||
'8C8QJyu5v5OUWdQZ4EA0d7ljeoTl50g8tpcGsDhnImLt+/jvJuFt8dECgYEAwD0n',
|
||||
'rhlkEjKVHxu1xwKeczxYCqqcUV9Quq8HnPh4VJQ77ljfZ57V7sAKrFDi5XfVD9jS',
|
||||
'oJPwxjw6za134VobhdvCM6WNs6AJmbR8E/b5kDMbGaZn27vt+/8JfnGaWBqpDi6W',
|
||||
'a5xoJOqmcMBQBK1YleZDoY4PLbk+onVKLMfGI/8CgYEAkyUIv8euGdGWpHnm5SdJ',
|
||||
'tLi5vv4Vs267uzntJWG/y3+DukTLgIdy7dgAI+pxkVgkg/+syUVSW5eU9CqZPyLl',
|
||||
'o8+Sqh2Jp36vTq71iSRj5RA5r3ND3K+8eFzPZzGj6AWUA1lrljFxzV7kLfiF8gH1',
|
||||
'FpvWUrhNoGT/vcFJno/uabECgYAecRC5hxfLserfVDoC261PvjyK492BHUDhbxob',
|
||||
'h1U2v4qGAdjOxd5Gwm5uPxjPEZzRt5oTB5pXKe5953xWWTiGh/hGyW6ZBTy/9E65',
|
||||
'sqBub0lZVHqZ1zamcwqD1WWFkiM3NbVoMQpk3iuhKzMAqpqekiofiSlqKi16+GvY',
|
||||
'j4IW7QKBgQCrIUckPZ6IY3ERIN1IL4TIcK2gOJcznp7fLWpC+sv35ya3OhtDXKFt',
|
||||
'GjIHmwLuiUNc0iPzA9Rw89W0zIkKWmWcxM88/ithdxh3MEeNDUGSnd4hQ9SECwxB',
|
||||
'Wem3eBT7I4VtFYoaTE3/bX1SKfgBdTzIRqWKSDpgBNZg/P2Tc+s11g==',
|
||||
'-----END RSA PRIVATE KEY-----',
|
||||
]
|
||||
|
||||
|
||||
pemKey = "\n".join(pemKeyArray)
|
||||
assert rsa('hello', pemKey, 'sha256') == 'PqHotvSEBvM/AejnMOWBXUcOf3uHtcGu2zAYdlYdnlNSSQ80Uq4lcyAEstnZ2AnQJ9l5TCC53uoRZ26GQ47zlACgqtYglmPhQKLvQ5fldRzeBauYhGgM2C0mUuUGxh074fNGbK+bgmwEmDMIrnSPtXwiCqTAHh+8VEnC7us3t09D61y298dPBJYEBNN3dFZT0w0pCIQg3j3DSiFJOCfywmOKyXqS1pvmk6A38DVclQZORQ5WZXp2yvSKRLjxpzjxDl76h1GfbBl7sMLEFMyzk0wyIhIz8ZELMibYn036G4X1IcSlDcimthEkIbn2QjM0ntyYDZIS4QnsMBjvkV2UHw=='
|
||||
assert rsa('poopy', pemKey, 'sha256') == 'or069qHwRDyl162T1s5G5+LfLnvDxlgk9kEsJvwI3vM02KB1LHW4+8gWqsV4TENZpeqed2Tb4na6ex+L/UR8JxJnnZtpVp33nUBgcp3miqp/YhcGN4++qolP4YN/21/AyfLFZW+VYggc+Mhh6PJSm+0dSEWMVsP35uH+35abXVxgB8GVOn7YTOSPaL8aw7hn4wlZWf2ieikKAi7AwAjkxnd7/Bu5+cW8D+ZdPHQfSKj+XHuPXlJNuQX0MDIqhdD2yuYJOQL56eKYs6nHPlClATkndSaAemQSGKet3X3Iz1awG4MGgz2Ei6bOanlNugc0f6Rng6rdwmqiMU3G4it6cw=='
|
||||
|
||||
assert jwt({'chicken': 'salad'}, encode(pemKey), 'sha256', True) == 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjaGlja2VuIjoic2FsYWQifQ.FSKD5Y6RNzkHTuHdvG3753U7QNZ-u-GUSPfP1FMjEaK0Rr_iyQTSSmHhkdYSFFnmBvrrN_l-UwKwir52WlsgmQm9HYm0kidxbj7fWwrK2E1oe0P7OjupFjv1BZxc5W69WeaHtOPWe28tiHiON1LCnax6HgfI5lcIBsESGIIBZMVeaioQn9gDVwea7JxJvAlrhDIWZowIHTIdCQocXip7g5jREWHeEIuJNug67mwnfAFxCjvTRiTd0Bw6oBwjM3FLya-RyEyWrejQOWSuC8CNWVUHISaSmEyZ7uM6wTi2m_58TaE9mQwlef32OPErPvvBpgL5pZIyQ4ymwrCIFQLBQQ'
|
||||
assert jwt({'lil': 'xan'}, encode('betrayed'), 'sha256', False) == 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsaWwiOiJ4YW4ifQ.md-oFvZagA-NXmZoRNyJOQ7zwK-PWUMmMQ_LI9ZOKaM'
|
||||
|
||||
assert crc32('hello', True) == 907060870
|
||||
assert crc32('tasty chicken breast :)', True) == 825820175
|
||||
assert crc32('21101:0.00123125:21102:-0.001:21100:0.710705:21103:-0.001:21096:0.71076:21104:-0.001:21094:1.0746:21105:-0.001:21093:0.710854:21106:-0.419:21092:0.01368102:21107:-0.001:21090:0.710975:21109:-0.001:21089:0.63586344:21110:-1.186213:21087:0.299:21111:-0.48751202:21086:0.9493:21112:-0.03702409:21082:0.03537667:21113:-0.712385:21081:0.00101366:21114:-0.2903:21079:0.710713:21115:-0.001:21078:0.997048:21116:-0.60089827:21077:0.23770225:21117:-0.83201:21076:0.03619135:21118:-0.09996142:21075:0.1272433:21119:-1.09681107:21074:0.7447885:21120:-0.04771792:21073:0.0011:21121:-0.91495684:21072:0.73311632:21122:-0.07940416:21071:0.09817:21123:-0.39376843:21070:0.19101052:21124:-1.51692599:21069:0.2757:21125:-0.11107322:21068:0.12480303:21126:-0.12704666:21067:0.4201:21128:-0.12804666', True) == -51055998
|
||||
|
||||
# assert eddsa('1b1b', privateKey, 'ed25519') == '3DBaaz8z4Pq9n6ncNCjB4pFLWaWTXbjaCUqKQmBgS3w7AP6opeDqANBhPssbV3jyfJB4LfK8kGR6pu6GU8fbjMuy'
|
||||
|
||||
69
ccxt/test/base/test_datetime.py
Normal file
69
ccxt/test/base/test_datetime.py
Normal file
@@ -0,0 +1,69 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.base.decimal_to_precision import ROUND # noqa E402
|
||||
from ccxt.base.decimal_to_precision import ROUND_UP # noqa E402
|
||||
from ccxt.base.decimal_to_precision import ROUND_DOWN # noqa E402
|
||||
import ccxt # noqa: F402
|
||||
|
||||
def test_datetime():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'regirock',
|
||||
})
|
||||
assert exchange.iso8601(514862627000) == '1986-04-26T01:23:47.000Z'
|
||||
assert exchange.iso8601(514862627559) == '1986-04-26T01:23:47.559Z'
|
||||
assert exchange.iso8601(514862627062) == '1986-04-26T01:23:47.062Z'
|
||||
assert exchange.iso8601(1) == '1970-01-01T00:00:00.001Z'
|
||||
assert exchange.iso8601(-1) is None
|
||||
# assert (exchange.iso8601 () === undefined);
|
||||
# todo: assert (exchange.iso8601 () === undefined);
|
||||
assert exchange.iso8601(None) is None
|
||||
assert exchange.iso8601('') is None
|
||||
assert exchange.iso8601('a') is None
|
||||
assert exchange.iso8601({}) is None
|
||||
# ----------------------------------------------------------------------------
|
||||
assert exchange.parse8601('1986-04-26T01:23:47.000Z') == 514862627000
|
||||
assert exchange.parse8601('1986-04-26T01:23:47.559Z') == 514862627559
|
||||
assert exchange.parse8601('1986-04-26T01:23:47.062Z') == 514862627062
|
||||
assert exchange.parse8601('1986-04-26T01:23:47.06Z') == 514862627060
|
||||
assert exchange.parse8601('1986-04-26T01:23:47.6Z') == 514862627600
|
||||
assert exchange.parse8601('1977-13-13T00:00:00.000Z') is None
|
||||
assert exchange.parse8601('1986-04-26T25:71:47.000Z') is None
|
||||
assert exchange.parse8601('3333') is None
|
||||
assert exchange.parse8601('Sr90') is None
|
||||
assert exchange.parse8601('') is None
|
||||
# assert (exchange.parse8601 () === undefined);
|
||||
# todo: assert (exchange.parse8601 () === undefined);
|
||||
assert exchange.parse8601(None) is None
|
||||
assert exchange.parse8601({}) is None
|
||||
assert exchange.parse8601(33) is None
|
||||
# ----------------------------------------------------------------------------
|
||||
assert exchange.parse_date('1986-04-26 00:00:00') == 514857600000
|
||||
assert exchange.parse_date('1986-04-26T01:23:47.000Z') == 514862627000
|
||||
assert exchange.parse_date('1986-13-13 00:00:00') is None
|
||||
# GMT formats (todo: bugs in php)
|
||||
# assert (exchange.parseDate ('Mon, 29 Apr 2024 14:00:17 GMT') === 1714399217000);
|
||||
# assert (exchange.parseDate ('Mon, 29 Apr 2024 14:09:17 GMT') === 1714399757000);
|
||||
# assert (exchange.parseDate ('Sun, 29 Dec 2024 01:01:10 GMT') === 1735434070000);
|
||||
# assert (exchange.parseDate ('Sun, 29 Dec 2024 02:11:10 GMT') === 1735438270000);
|
||||
# assert (exchange.parseDate ('Sun, 08 Dec 2024 02:03:04 GMT') === 1733623384000);
|
||||
assert exchange.round_timeframe('5m', exchange.parse8601('2019-08-12 13:22:08'), ROUND_DOWN) == exchange.parse8601('2019-08-12 13:20:00')
|
||||
assert exchange.round_timeframe('10m', exchange.parse8601('2019-08-12 13:22:08'), ROUND_DOWN) == exchange.parse8601('2019-08-12 13:20:00')
|
||||
assert exchange.round_timeframe('30m', exchange.parse8601('2019-08-12 13:22:08'), ROUND_DOWN) == exchange.parse8601('2019-08-12 13:00:00')
|
||||
assert exchange.round_timeframe('1d', exchange.parse8601('2019-08-12 13:22:08'), ROUND_DOWN) == exchange.parse8601('2019-08-12 00:00:00')
|
||||
assert exchange.round_timeframe('5m', exchange.parse8601('2019-08-12 13:22:08'), ROUND_UP) == exchange.parse8601('2019-08-12 13:25:00')
|
||||
assert exchange.round_timeframe('10m', exchange.parse8601('2019-08-12 13:22:08'), ROUND_UP) == exchange.parse8601('2019-08-12 13:30:00')
|
||||
assert exchange.round_timeframe('30m', exchange.parse8601('2019-08-12 13:22:08'), ROUND_UP) == exchange.parse8601('2019-08-12 13:30:00')
|
||||
assert exchange.round_timeframe('1h', exchange.parse8601('2019-08-12 13:22:08'), ROUND_UP) == exchange.parse8601('2019-08-12 14:00:00')
|
||||
assert exchange.round_timeframe('1d', exchange.parse8601('2019-08-12 13:22:08'), ROUND_UP) == exchange.parse8601('2019-08-13 00:00:00')
|
||||
325
ccxt/test/base/test_decimal_to_precision.py
Normal file
325
ccxt/test/base/test_decimal_to_precision.py
Normal file
@@ -0,0 +1,325 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.base.decimal_to_precision import DECIMAL_PLACES # noqa E402
|
||||
from ccxt.base.decimal_to_precision import TICK_SIZE # noqa E402
|
||||
from ccxt.base.decimal_to_precision import NO_PADDING # noqa E402
|
||||
from ccxt.base.decimal_to_precision import TRUNCATE # noqa E402
|
||||
from ccxt.base.decimal_to_precision import ROUND # noqa E402
|
||||
from ccxt.base.decimal_to_precision import SIGNIFICANT_DIGITS # noqa E402
|
||||
from ccxt.base.decimal_to_precision import PAD_WITH_ZERO # noqa E402
|
||||
from ccxt.base.decimal_to_precision import decimal_to_precision # noqa E402
|
||||
import ccxt # noqa: F402
|
||||
|
||||
def test_decimal_to_precision():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'regirock',
|
||||
})
|
||||
# ----------------------------------------------------------------------------
|
||||
# Truncate To N Digits After Dot
|
||||
assert exchange.decimal_to_precision('12.3456000', TRUNCATE, 100, DECIMAL_PLACES) == '12.3456'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, 100, DECIMAL_PLACES) == '12.3456'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, 4, DECIMAL_PLACES) == '12.3456'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, 3, DECIMAL_PLACES) == '12.345'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, 2, DECIMAL_PLACES) == '12.34'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, 1, DECIMAL_PLACES) == '12.3'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, 0, DECIMAL_PLACES) == '12'
|
||||
# ['12.3456', TRUNCATE, -1, DECIMAL_PLACES, '10'], # not yet supported
|
||||
# ['123.456', TRUNCATE, -2, DECIMAL_PLACES, '120'], # not yet supported
|
||||
# ['123.456', TRUNCATE, -3, DECIMAL_PLACES, '100'], # not yet supported
|
||||
assert exchange.decimal_to_precision('0.0000001', TRUNCATE, 8, DECIMAL_PLACES) == '0.0000001'
|
||||
assert exchange.decimal_to_precision('0.00000001', TRUNCATE, 8, DECIMAL_PLACES) == '0.00000001'
|
||||
assert exchange.decimal_to_precision('0.000000000', TRUNCATE, 9, DECIMAL_PLACES, PAD_WITH_ZERO) == '0.000000000'
|
||||
assert exchange.decimal_to_precision('0.000000001', TRUNCATE, 9, DECIMAL_PLACES, PAD_WITH_ZERO) == '0.000000001'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, -1, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('123.456', TRUNCATE, -1, DECIMAL_PLACES) == '120'
|
||||
assert exchange.decimal_to_precision('123.456', TRUNCATE, -2, DECIMAL_PLACES) == '100'
|
||||
assert exchange.decimal_to_precision('9.99999', TRUNCATE, -1, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('99.9999', TRUNCATE, -1, DECIMAL_PLACES) == '90'
|
||||
assert exchange.decimal_to_precision('99.9999', TRUNCATE, -2, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('0', TRUNCATE, 0, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('-0.9', TRUNCATE, 0, DECIMAL_PLACES) == '0'
|
||||
# ----------------------------------------------------------------------------
|
||||
# Truncate To N Significant Digits
|
||||
assert exchange.decimal_to_precision('0.000123456700', TRUNCATE, 100, SIGNIFICANT_DIGITS) == '0.0001234567'
|
||||
assert exchange.decimal_to_precision('0.0001234567', TRUNCATE, 100, SIGNIFICANT_DIGITS) == '0.0001234567'
|
||||
assert exchange.decimal_to_precision('0.0001234567', TRUNCATE, 7, SIGNIFICANT_DIGITS) == '0.0001234567'
|
||||
assert exchange.decimal_to_precision('0.000123456', TRUNCATE, 6, SIGNIFICANT_DIGITS) == '0.000123456'
|
||||
assert exchange.decimal_to_precision('0.000123456', TRUNCATE, 5, SIGNIFICANT_DIGITS) == '0.00012345'
|
||||
assert exchange.decimal_to_precision('0.000123456', TRUNCATE, 2, SIGNIFICANT_DIGITS) == '0.00012'
|
||||
assert exchange.decimal_to_precision('0.000123456', TRUNCATE, 1, SIGNIFICANT_DIGITS) == '0.0001'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 10, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '123.0000987'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 8, SIGNIFICANT_DIGITS) == '123.00009'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 7, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '123.0000'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 6, SIGNIFICANT_DIGITS) == '123'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 5, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '123.00'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 4, SIGNIFICANT_DIGITS) == '123'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 4, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '123.0'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 3, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '123'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 2, SIGNIFICANT_DIGITS) == '120'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 1, SIGNIFICANT_DIGITS) == '100'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 1, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '100'
|
||||
assert exchange.decimal_to_precision('1234', TRUNCATE, 5, SIGNIFICANT_DIGITS) == '1234'
|
||||
assert exchange.decimal_to_precision('1234', TRUNCATE, 5, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '1234.0'
|
||||
assert exchange.decimal_to_precision('1234', TRUNCATE, 4, SIGNIFICANT_DIGITS) == '1234'
|
||||
assert exchange.decimal_to_precision('1234', TRUNCATE, 4, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '1234'
|
||||
assert exchange.decimal_to_precision('1234.69', TRUNCATE, 0, SIGNIFICANT_DIGITS) == '0'
|
||||
assert exchange.decimal_to_precision('1234.69', TRUNCATE, 0, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '0'
|
||||
# ----------------------------------------------------------------------------
|
||||
# Round To N Digits After Dot
|
||||
assert exchange.decimal_to_precision('12.3456000', ROUND, 100, DECIMAL_PLACES) == '12.3456'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, 100, DECIMAL_PLACES) == '12.3456'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, 4, DECIMAL_PLACES) == '12.3456'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, 3, DECIMAL_PLACES) == '12.346'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, 2, DECIMAL_PLACES) == '12.35'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, 1, DECIMAL_PLACES) == '12.3'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, 0, DECIMAL_PLACES) == '12'
|
||||
# todo:
|
||||
# ['9.999', ROUND, 3, DECIMAL_PLACES, NO_PADDING, '9.999'],
|
||||
# ['9.999', ROUND, 2, DECIMAL_PLACES, NO_PADDING, '10'],
|
||||
# ['9.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO, '10.00'],
|
||||
# ['99.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO, '100.00'],
|
||||
# ['-99.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO, '-100.00'],
|
||||
# ['12.3456', ROUND, -1, DECIMAL_PLACES, NO_PADDING, '10'], # not yet supported
|
||||
# ['123.456', ROUND, -1, DECIMAL_PLACES, NO_PADDING, '120'], # not yet supported
|
||||
# ['123.456', ROUND, -2, DECIMAL_PLACES, NO_PADDING, '100'], # not yet supported
|
||||
# a problematic case in PHP
|
||||
assert exchange.decimal_to_precision('10000', ROUND, 6, DECIMAL_PLACES) == '10000'
|
||||
assert exchange.decimal_to_precision('0.00003186', ROUND, 8, DECIMAL_PLACES) == '0.00003186'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, -1, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('123.456', ROUND, -1, DECIMAL_PLACES) == '120'
|
||||
assert exchange.decimal_to_precision('123.456', ROUND, -2, DECIMAL_PLACES) == '100'
|
||||
assert exchange.decimal_to_precision('9.99999', ROUND, -1, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('99.9999', ROUND, -1, DECIMAL_PLACES) == '100'
|
||||
assert exchange.decimal_to_precision('99.9999', ROUND, -2, DECIMAL_PLACES) == '100'
|
||||
assert exchange.decimal_to_precision('9.999', ROUND, 3, DECIMAL_PLACES) == '9.999'
|
||||
assert exchange.decimal_to_precision('9.999', ROUND, 2, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('9.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO) == '10.00'
|
||||
assert exchange.decimal_to_precision('99.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO) == '100.00'
|
||||
assert exchange.decimal_to_precision('-99.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO) == '-100.00'
|
||||
# ----------------------------------------------------------------------------
|
||||
# Round To N Significant Digits
|
||||
assert exchange.decimal_to_precision('0.000123456700', ROUND, 100, SIGNIFICANT_DIGITS) == '0.0001234567'
|
||||
assert exchange.decimal_to_precision('0.0001234567', ROUND, 100, SIGNIFICANT_DIGITS) == '0.0001234567'
|
||||
assert exchange.decimal_to_precision('0.0001234567', ROUND, 7, SIGNIFICANT_DIGITS) == '0.0001234567'
|
||||
assert exchange.decimal_to_precision('0.000123456', ROUND, 6, SIGNIFICANT_DIGITS) == '0.000123456'
|
||||
assert exchange.decimal_to_precision('0.000123456', ROUND, 5, SIGNIFICANT_DIGITS) == '0.00012346'
|
||||
assert exchange.decimal_to_precision('0.000123456', ROUND, 4, SIGNIFICANT_DIGITS) == '0.0001235'
|
||||
assert exchange.decimal_to_precision('0.00012', ROUND, 2, SIGNIFICANT_DIGITS) == '0.00012'
|
||||
assert exchange.decimal_to_precision('0.0001', ROUND, 1, SIGNIFICANT_DIGITS) == '0.0001'
|
||||
assert exchange.decimal_to_precision('123.0000987654', ROUND, 7, SIGNIFICANT_DIGITS) == '123.0001'
|
||||
assert exchange.decimal_to_precision('123.0000987654', ROUND, 6, SIGNIFICANT_DIGITS) == '123'
|
||||
assert exchange.decimal_to_precision('0.00098765', ROUND, 2, SIGNIFICANT_DIGITS) == '0.00099'
|
||||
assert exchange.decimal_to_precision('0.00098765', ROUND, 2, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '0.00099'
|
||||
assert exchange.decimal_to_precision('0.00098765', ROUND, 1, SIGNIFICANT_DIGITS) == '0.001'
|
||||
assert exchange.decimal_to_precision('0.00098765', ROUND, 10, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '0.0009876500000'
|
||||
assert exchange.decimal_to_precision('0.098765', ROUND, 1, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '0.1'
|
||||
assert exchange.decimal_to_precision('0', ROUND, 0, SIGNIFICANT_DIGITS) == '0'
|
||||
assert exchange.decimal_to_precision('-0.123', ROUND, 0, SIGNIFICANT_DIGITS) == '0'
|
||||
assert exchange.decimal_to_precision('0.00000044', ROUND, 5, SIGNIFICANT_DIGITS) == '0.00000044'
|
||||
assert exchange.decimal_to_precision('0.123456', ROUND, 5, SIGNIFICANT_DIGITS) == '0.12346'
|
||||
assert exchange.decimal_to_precision('0.123456', ROUND, 6, SIGNIFICANT_DIGITS) == '0.123456'
|
||||
assert exchange.decimal_to_precision('0.123456', ROUND, 7, SIGNIFICANT_DIGITS) == '0.123456'
|
||||
assert exchange.decimal_to_precision('1.234567', ROUND, 5, SIGNIFICANT_DIGITS) == '1.2346'
|
||||
assert exchange.decimal_to_precision('1.234567', ROUND, 6, SIGNIFICANT_DIGITS) == '1.23457'
|
||||
assert exchange.decimal_to_precision('1.234567', ROUND, 7, SIGNIFICANT_DIGITS) == '1.234567'
|
||||
assert exchange.decimal_to_precision('12.34567', ROUND, 5, SIGNIFICANT_DIGITS) == '12.346'
|
||||
assert exchange.decimal_to_precision('12.34567', ROUND, 6, SIGNIFICANT_DIGITS) == '12.3457'
|
||||
assert exchange.decimal_to_precision('12.34567', ROUND, 7, SIGNIFICANT_DIGITS) == '12.34567'
|
||||
# above 1.0
|
||||
assert exchange.decimal_to_precision('1114.5', ROUND, 3, SIGNIFICANT_DIGITS) == '1110'
|
||||
assert exchange.decimal_to_precision('1115.5', ROUND, 3, SIGNIFICANT_DIGITS) == '1120'
|
||||
assert exchange.decimal_to_precision('1114.5', ROUND, 4, SIGNIFICANT_DIGITS) == '1115'
|
||||
assert exchange.decimal_to_precision('1114.5', ROUND, 5, SIGNIFICANT_DIGITS) == '1114.5'
|
||||
assert exchange.decimal_to_precision('1115.5', ROUND, 5, SIGNIFICANT_DIGITS) == '1115.5'
|
||||
# ----------------------------------------------------------------------------
|
||||
# Round To Tick Size
|
||||
assert exchange.decimal_to_precision('0.000123456700', ROUND, 0.00012, TICK_SIZE) == '0.00012'
|
||||
assert exchange.decimal_to_precision('0.0001234567', ROUND, 0.00013, TICK_SIZE) == '0.00013'
|
||||
assert exchange.decimal_to_precision('0.0001234567', TRUNCATE, 0.00013, TICK_SIZE) == '0'
|
||||
assert exchange.decimal_to_precision('101.000123456700', ROUND, 100, TICK_SIZE) == '100'
|
||||
assert exchange.decimal_to_precision('0.000123456700', ROUND, 100, TICK_SIZE) == '0'
|
||||
assert exchange.decimal_to_precision('165', TRUNCATE, 110, TICK_SIZE) == '110'
|
||||
assert exchange.decimal_to_precision('3210', TRUNCATE, 1110, TICK_SIZE) == '2220'
|
||||
assert exchange.decimal_to_precision('165', ROUND, 110, TICK_SIZE) == '220'
|
||||
assert exchange.decimal_to_precision('0.000123456789', ROUND, 1.2e-7, TICK_SIZE) == '0.00012348'
|
||||
assert exchange.decimal_to_precision('0.000123456789', TRUNCATE, 1.2e-7, TICK_SIZE) == '0.00012336'
|
||||
assert exchange.decimal_to_precision('0.000273398', ROUND, 1e-7, TICK_SIZE) == '0.0002734'
|
||||
assert exchange.decimal_to_precision('0.00005714', TRUNCATE, 1e-8, TICK_SIZE) == '0.00005714'
|
||||
# this line causes problems in JS, fix with Precise
|
||||
# assert (exchange.decimalToPrecision ('0.0000571495257361', TRUNCATE, 0.00000001, TICK_SIZE) === '0.00005714');
|
||||
assert exchange.decimal_to_precision('0.01', ROUND, 0.0001, TICK_SIZE, PAD_WITH_ZERO) == '0.0100'
|
||||
assert exchange.decimal_to_precision('0.01', TRUNCATE, 0.0001, TICK_SIZE, PAD_WITH_ZERO) == '0.0100'
|
||||
assert exchange.decimal_to_precision('-0.000123456789', ROUND, 1.2e-7, TICK_SIZE) == '-0.00012348'
|
||||
assert exchange.decimal_to_precision('-0.000123456789', TRUNCATE, 1.2e-7, TICK_SIZE) == '-0.00012336'
|
||||
assert exchange.decimal_to_precision('-165', TRUNCATE, 110, TICK_SIZE) == '-110'
|
||||
assert exchange.decimal_to_precision('-165', ROUND, 110, TICK_SIZE) == '-220'
|
||||
assert exchange.decimal_to_precision('-1650', TRUNCATE, 1100, TICK_SIZE) == '-1100'
|
||||
assert exchange.decimal_to_precision('-1650', ROUND, 1100, TICK_SIZE) == '-2200'
|
||||
assert exchange.decimal_to_precision('0.0006', TRUNCATE, 0.0001, TICK_SIZE) == '0.0006'
|
||||
assert exchange.decimal_to_precision('-0.0006', TRUNCATE, 0.0001, TICK_SIZE) == '-0.0006'
|
||||
assert exchange.decimal_to_precision('0.6', TRUNCATE, 0.2, TICK_SIZE) == '0.6'
|
||||
assert exchange.decimal_to_precision('-0.6', TRUNCATE, 0.2, TICK_SIZE) == '-0.6'
|
||||
assert exchange.decimal_to_precision('1.2', ROUND, 0.4, TICK_SIZE) == '1.2'
|
||||
assert exchange.decimal_to_precision('-1.2', ROUND, 0.4, TICK_SIZE) == '-1.2'
|
||||
assert exchange.decimal_to_precision('1.2', ROUND, 0.02, TICK_SIZE) == '1.2'
|
||||
assert exchange.decimal_to_precision('-1.2', ROUND, 0.02, TICK_SIZE) == '-1.2'
|
||||
assert exchange.decimal_to_precision('44', ROUND, 4.4, TICK_SIZE) == '44'
|
||||
assert exchange.decimal_to_precision('-44', ROUND, 4.4, TICK_SIZE) == '-44'
|
||||
assert exchange.decimal_to_precision('44.00000001', ROUND, 4.4, TICK_SIZE) == '44'
|
||||
assert exchange.decimal_to_precision('-44.00000001', ROUND, 4.4, TICK_SIZE) == '-44'
|
||||
# https://github.com/ccxt/ccxt/issues/6731
|
||||
assert exchange.decimal_to_precision('20', TRUNCATE, 1e-8, TICK_SIZE) == '20'
|
||||
assert exchange.decimal_to_precision('0.000123456789', TRUNCATE, 1e-8, TICK_SIZE) == '0.00012345'
|
||||
# ----------------------------------------------------------------------------
|
||||
# Negative Numbers
|
||||
assert exchange.decimal_to_precision('-0.123456', TRUNCATE, 5, DECIMAL_PLACES) == '-0.12345'
|
||||
assert exchange.decimal_to_precision('-0.123456', ROUND, 5, DECIMAL_PLACES) == '-0.12346'
|
||||
# ----------------------------------------------------------------------------
|
||||
# without dot / trailing dot
|
||||
assert exchange.decimal_to_precision('123', TRUNCATE, 0) == '123'
|
||||
assert exchange.decimal_to_precision('123', TRUNCATE, 5, DECIMAL_PLACES) == '123'
|
||||
assert exchange.decimal_to_precision('123', TRUNCATE, 5, DECIMAL_PLACES, PAD_WITH_ZERO) == '123.00000'
|
||||
assert exchange.decimal_to_precision('123.', TRUNCATE, 0, DECIMAL_PLACES) == '123'
|
||||
assert exchange.decimal_to_precision('123.', TRUNCATE, 5, DECIMAL_PLACES, PAD_WITH_ZERO) == '123.00000'
|
||||
assert exchange.decimal_to_precision('0.', TRUNCATE, 0) == '0'
|
||||
assert exchange.decimal_to_precision('0.', TRUNCATE, 5, DECIMAL_PLACES, PAD_WITH_ZERO) == '0.00000'
|
||||
# ----------------------------------------------------------------------------
|
||||
# rounding for equidistant digits
|
||||
assert exchange.decimal_to_precision('1.44', ROUND, 1, DECIMAL_PLACES) == '1.4'
|
||||
assert exchange.decimal_to_precision('1.45', ROUND, 1, DECIMAL_PLACES) == '1.5'
|
||||
assert exchange.decimal_to_precision('1.45', ROUND, 0, DECIMAL_PLACES) == '1' # not 2
|
||||
# ----------------------------------------------------------------------------
|
||||
# negative precision only implemented so far in python
|
||||
# pretty useless for decimal applications as anything |x| < 5 === 0
|
||||
# NO_PADDING and PAD_WITH_ZERO are ignored
|
||||
assert exchange.decimal_to_precision('5', ROUND, -1, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('4.999', ROUND, -1, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('0.0431531423', ROUND, -1, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('-69.3', ROUND, -1, DECIMAL_PLACES) == '-70'
|
||||
assert exchange.decimal_to_precision('5001', ROUND, -4, DECIMAL_PLACES) == '10000'
|
||||
assert exchange.decimal_to_precision('4999.999', ROUND, -4, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('69.3', TRUNCATE, -2, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('-69.3', TRUNCATE, -2, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('69.3', TRUNCATE, -1, SIGNIFICANT_DIGITS) == '60'
|
||||
assert exchange.decimal_to_precision('-69.3', TRUNCATE, -1, SIGNIFICANT_DIGITS) == '-60'
|
||||
assert exchange.decimal_to_precision('69.3', TRUNCATE, -2, SIGNIFICANT_DIGITS) == '0'
|
||||
assert exchange.decimal_to_precision('1602000000000000000000', TRUNCATE, 3, SIGNIFICANT_DIGITS) == '1600000000000000000000'
|
||||
# ----------------------------------------------------------------------------
|
||||
# stringified precision
|
||||
assert exchange.decimal_to_precision('-0.000123456789', ROUND, '0.00000012', TICK_SIZE) == '-0.00012348'
|
||||
assert exchange.decimal_to_precision('-0.000123456789', TRUNCATE, '0.00000012', TICK_SIZE) == '-0.00012336'
|
||||
assert exchange.decimal_to_precision('-165', TRUNCATE, '110', TICK_SIZE) == '-110'
|
||||
assert exchange.decimal_to_precision('-165', ROUND, '110', TICK_SIZE) == '-220'
|
||||
# ----------------------------------------------------------------------------
|
||||
# testDecimalToPrecisionErrorHandling (todo)
|
||||
#
|
||||
# throws (() =>
|
||||
# decimalToPrecision ('123456.789', TRUNCATE, -2, DECIMAL_PLACES),
|
||||
# 'negative precision is not yet supported')
|
||||
#
|
||||
# throws (() =>
|
||||
# decimalToPrecision ('foo'),
|
||||
# "invalid number (contains an illegal character 'f')")
|
||||
#
|
||||
# throws (() =>
|
||||
# decimalToPrecision ('0.01', TRUNCATE, -1, TICK_SIZE),
|
||||
# "TICK_SIZE cant be used with negative numPrecisionDigits")
|
||||
# ----------------------------------------------------------------------------
|
||||
# Additional Edge Cases
|
||||
# Zero handling variations
|
||||
assert exchange.decimal_to_precision('0.0', TRUNCATE, 2, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('0.00', ROUND, 3, DECIMAL_PLACES, PAD_WITH_ZERO) == '0.000'
|
||||
assert exchange.decimal_to_precision('-0.0', TRUNCATE, 2, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('-0.00', ROUND, 1, DECIMAL_PLACES) == '0'
|
||||
# Very small numbers close to zero
|
||||
assert exchange.decimal_to_precision('0.0000000001', TRUNCATE, 8, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('0.0000000001', ROUND, 8, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('0.0000000001', TRUNCATE, 10, DECIMAL_PLACES) == '0.0000000001'
|
||||
assert exchange.decimal_to_precision('0.00000000009', ROUND, 10, DECIMAL_PLACES) == '0.0000000001'
|
||||
assert exchange.decimal_to_precision('0.00000000015', ROUND, 10, DECIMAL_PLACES) == '0.0000000002'
|
||||
# Very large numbers
|
||||
assert exchange.decimal_to_precision('99999999999999.99999', TRUNCATE, 2, DECIMAL_PLACES) == '99999999999999.99'
|
||||
assert exchange.decimal_to_precision('99999999999999.99999', ROUND, 2, DECIMAL_PLACES) == '100000000000000'
|
||||
assert exchange.decimal_to_precision('123456789012345', TRUNCATE, 3, SIGNIFICANT_DIGITS) == '123000000000000'
|
||||
assert exchange.decimal_to_precision('123456789012345', ROUND, 3, SIGNIFICANT_DIGITS) == '123000000000000'
|
||||
# Numbers with leading zeros
|
||||
assert exchange.decimal_to_precision('000123.456', TRUNCATE, 2, DECIMAL_PLACES) == '123.45'
|
||||
assert exchange.decimal_to_precision('000123.456', ROUND, 2, DECIMAL_PLACES) == '123.46'
|
||||
assert exchange.decimal_to_precision('0000.123', TRUNCATE, 2, DECIMAL_PLACES) == '0.12'
|
||||
# Boundary rounding cases (exactly at 0.5)
|
||||
assert exchange.decimal_to_precision('1.5', ROUND, 0, DECIMAL_PLACES) == '2'
|
||||
assert exchange.decimal_to_precision('2.5', ROUND, 0, DECIMAL_PLACES) == '3'
|
||||
assert exchange.decimal_to_precision('-1.5', ROUND, 0, DECIMAL_PLACES) == '-2'
|
||||
assert exchange.decimal_to_precision('-2.5', ROUND, 0, DECIMAL_PLACES) == '-3'
|
||||
assert exchange.decimal_to_precision('1.25', ROUND, 1, DECIMAL_PLACES) == '1.3'
|
||||
assert exchange.decimal_to_precision('1.35', ROUND, 1, DECIMAL_PLACES) == '1.4'
|
||||
# Carry-over in rounding (cascading effects)
|
||||
assert exchange.decimal_to_precision('9.999999', ROUND, 0, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('99.999999', ROUND, 0, DECIMAL_PLACES) == '100'
|
||||
assert exchange.decimal_to_precision('999.999999', ROUND, 0, DECIMAL_PLACES) == '1000'
|
||||
assert exchange.decimal_to_precision('9.999999', ROUND, 1, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('9.999999', ROUND, 2, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('-9.999999', ROUND, 0, DECIMAL_PLACES) == '-10'
|
||||
assert exchange.decimal_to_precision('-99.999999', ROUND, 0, DECIMAL_PLACES) == '-100'
|
||||
# Edge cases for TICK_SIZE with very small ticks
|
||||
assert exchange.decimal_to_precision('1.2345', ROUND, 0.0001, TICK_SIZE) == '1.2345'
|
||||
assert exchange.decimal_to_precision('1.23456', ROUND, 0.0001, TICK_SIZE) == '1.2346'
|
||||
assert exchange.decimal_to_precision('1.23454', ROUND, 0.0001, TICK_SIZE) == '1.2345'
|
||||
assert exchange.decimal_to_precision('1.23444', TRUNCATE, 0.0001, TICK_SIZE) == '1.2344'
|
||||
# TICK_SIZE with numbers smaller than tick
|
||||
assert exchange.decimal_to_precision('0.05', ROUND, 0.1, TICK_SIZE) == '0.1'
|
||||
assert exchange.decimal_to_precision('0.04', ROUND, 0.1, TICK_SIZE) == '0'
|
||||
assert exchange.decimal_to_precision('0.04', TRUNCATE, 0.1, TICK_SIZE) == '0'
|
||||
assert exchange.decimal_to_precision('0.049999', ROUND, 0.1, TICK_SIZE) == '0'
|
||||
# SIGNIFICANT_DIGITS edge cases
|
||||
assert exchange.decimal_to_precision('10000000', TRUNCATE, 1, SIGNIFICANT_DIGITS) == '10000000'
|
||||
assert exchange.decimal_to_precision('10000001', TRUNCATE, 1, SIGNIFICANT_DIGITS) == '10000000'
|
||||
assert exchange.decimal_to_precision('19999999', TRUNCATE, 1, SIGNIFICANT_DIGITS) == '10000000'
|
||||
assert exchange.decimal_to_precision('19999999', ROUND, 1, SIGNIFICANT_DIGITS) == '20000000'
|
||||
# Precision with PAD_WITH_ZERO edge cases
|
||||
assert exchange.decimal_to_precision('1', TRUNCATE, 0, DECIMAL_PLACES, PAD_WITH_ZERO) == '1'
|
||||
assert exchange.decimal_to_precision('1.0', TRUNCATE, 0, DECIMAL_PLACES, PAD_WITH_ZERO) == '1'
|
||||
assert exchange.decimal_to_precision('1', TRUNCATE, 3, DECIMAL_PLACES, PAD_WITH_ZERO) == '1.000'
|
||||
assert exchange.decimal_to_precision('1.1', TRUNCATE, 5, DECIMAL_PLACES, PAD_WITH_ZERO) == '1.10000'
|
||||
# Numbers that are exactly multiples of precision
|
||||
assert exchange.decimal_to_precision('1.2', TRUNCATE, 0.1, TICK_SIZE) == '1.2'
|
||||
assert exchange.decimal_to_precision('1.2', ROUND, 0.1, TICK_SIZE) == '1.2'
|
||||
assert exchange.decimal_to_precision('12', TRUNCATE, 4, TICK_SIZE) == '12'
|
||||
assert exchange.decimal_to_precision('12', ROUND, 4, TICK_SIZE) == '12'
|
||||
# Very high precision values
|
||||
assert exchange.decimal_to_precision('1.123456789012345', TRUNCATE, 15, DECIMAL_PLACES) == '1.123456789012345'
|
||||
assert exchange.decimal_to_precision('1.123456789012345', TRUNCATE, 10, DECIMAL_PLACES) == '1.123456789'
|
||||
assert exchange.decimal_to_precision('1.123456789012345', TRUNCATE, 10, DECIMAL_PLACES, PAD_WITH_ZERO) == '1.1234567890'
|
||||
assert exchange.decimal_to_precision('0.123456789012345', TRUNCATE, 15, SIGNIFICANT_DIGITS) == '0.123456789012345'
|
||||
# Mixed large and small components
|
||||
assert exchange.decimal_to_precision('1000000.000001', TRUNCATE, 6, DECIMAL_PLACES) == '1000000.000001'
|
||||
assert exchange.decimal_to_precision('1000000.000001', TRUNCATE, 5, DECIMAL_PLACES, PAD_WITH_ZERO) == '1000000.00000'
|
||||
assert exchange.decimal_to_precision('1000000.000001', ROUND, 5, DECIMAL_PLACES, PAD_WITH_ZERO) == '1000000.00000'
|
||||
# Edge cases around 1.0 boundary for significant digits
|
||||
assert exchange.decimal_to_precision('0.999999', ROUND, 1, SIGNIFICANT_DIGITS) == '1'
|
||||
assert exchange.decimal_to_precision('0.999999', ROUND, 2, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '1.0'
|
||||
assert exchange.decimal_to_precision('0.999999', ROUND, 3, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '1.00'
|
||||
assert exchange.decimal_to_precision('0.999949', ROUND, 4, SIGNIFICANT_DIGITS) == '0.9999'
|
||||
assert exchange.decimal_to_precision('0.999951', ROUND, 4, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '1.000'
|
||||
# ----------------------------------------------------------------------------
|
||||
# https://github.com/ccxt/ccxt/issues/11765
|
||||
assert exchange.decimal_to_precision('123456.12345678912', TRUNCATE, 1e-8, TICK_SIZE) == '123456.12345678'
|
||||
# todo: not sure about below
|
||||
assert exchange.decimal_to_precision('123456.12345674999', TRUNCATE, 5e-8, TICK_SIZE) == '123456.1234567'
|
||||
assert exchange.decimal_to_precision('123456.12345674999', TRUNCATE, 5e-8, TICK_SIZE, PAD_WITH_ZERO) == '123456.12345670'
|
||||
assert exchange.decimal_to_precision('123456.12345675001', TRUNCATE, 5e-8, TICK_SIZE) == '123456.12345675'
|
||||
assert exchange.decimal_to_precision('123456.50000000001', TRUNCATE, 0.5, TICK_SIZE, PAD_WITH_ZERO) == '123456.5'
|
||||
assert exchange.decimal_to_precision('123456.49999999999', TRUNCATE, 0.5, TICK_SIZE, PAD_WITH_ZERO) == '123456.0'
|
||||
assert exchange.decimal_to_precision('123456.12345678912', TRUNCATE, '0.00000001', TICK_SIZE) == '123456.12345678'
|
||||
23
ccxt/test/base/test_deep_extend.py
Normal file
23
ccxt/test/base/test_deep_extend.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
def test_deep_extend():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
})
|
||||
assert exchange.parse_to_numeric('1') == 1
|
||||
return True # dummy for now
|
||||
82
ccxt/test/base/test_extend.py
Normal file
82
ccxt/test/base/test_extend.py
Normal file
@@ -0,0 +1,82 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
|
||||
def test_extend():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'regirock',
|
||||
})
|
||||
obj1 = {
|
||||
'a': 1,
|
||||
'b': [1, 2],
|
||||
'c': [{
|
||||
'test1': 1,
|
||||
'test2': 1,
|
||||
}],
|
||||
'd': None,
|
||||
'e': 'not_undefined',
|
||||
'sub': {
|
||||
'a': 1,
|
||||
'b': [1, 2],
|
||||
'c': [{
|
||||
'test1': 1,
|
||||
'test2': 2,
|
||||
}],
|
||||
'd': None,
|
||||
'e': 'not_undefined',
|
||||
'other1': 'x',
|
||||
},
|
||||
'other1': 'x',
|
||||
}
|
||||
obj2 = {
|
||||
'a': 2,
|
||||
'b': [3, 4],
|
||||
'c': [{
|
||||
'test1': 2,
|
||||
'test3': 3,
|
||||
}],
|
||||
'd': 'not_undefined',
|
||||
'e': None,
|
||||
'sub': {
|
||||
'a': 2,
|
||||
'b': [3, 4],
|
||||
'c': [{
|
||||
'test1': 2,
|
||||
'test3': 3,
|
||||
}],
|
||||
'd': 'not_undefined',
|
||||
'e': None,
|
||||
'other2': 'y',
|
||||
},
|
||||
'other2': 'y',
|
||||
}
|
||||
# extend
|
||||
extended = exchange.extend(obj1, obj2)
|
||||
tbfe_check_extended(extended, True)
|
||||
|
||||
|
||||
def tbfe_check_extended(extended, has_sub):
|
||||
assert extended['a'] == 2
|
||||
assert extended['b'][0] == 3
|
||||
assert extended['b'][1] == 4
|
||||
assert extended['c'][0]['test1'] == 2
|
||||
assert not ('test2' in extended['c'][0])
|
||||
assert extended['c'][0]['test3'] == 3
|
||||
assert extended['d'] == 'not_undefined'
|
||||
assert extended['e'] is None
|
||||
assert extended['other1'] == 'x'
|
||||
assert extended['other2'] == 'y'
|
||||
if has_sub:
|
||||
assert 'sub' in extended
|
||||
49
ccxt/test/base/test_filter_by.py
Normal file
49
ccxt/test/base/test_filter_by.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
def test_filter_by():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
})
|
||||
sample_array = [{
|
||||
'foo': 'a',
|
||||
}, {
|
||||
'foo': None,
|
||||
}, {
|
||||
'foo': 'b',
|
||||
}, {
|
||||
'foo': 'a',
|
||||
'bar': 'b',
|
||||
}, {
|
||||
'foo': 'c',
|
||||
}, {
|
||||
'foo': 'd',
|
||||
}, {
|
||||
'foo': 'b',
|
||||
}, {
|
||||
'foo': 'c',
|
||||
}, {
|
||||
'foo': 'c',
|
||||
}]
|
||||
current_value = exchange.filter_by(sample_array, 'foo', 'a')
|
||||
stored_value = [{
|
||||
'foo': 'a',
|
||||
}, {
|
||||
'foo': 'a',
|
||||
'bar': 'b',
|
||||
}]
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'testFilterBy', current_value, stored_value)
|
||||
53
ccxt/test/base/test_group_by.py
Normal file
53
ccxt/test/base/test_group_by.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
def test_group_by():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
})
|
||||
sample_array = [{
|
||||
'foo': 'a',
|
||||
}, {
|
||||
'foo': 'b',
|
||||
}, {
|
||||
'foo': 'c',
|
||||
}, {
|
||||
'foo': 'b',
|
||||
}, {
|
||||
'foo': 'c',
|
||||
}, {
|
||||
'foo': 'c',
|
||||
}]
|
||||
current_value = exchange.group_by(sample_array, 'foo')
|
||||
stored_value = {
|
||||
'a': [{
|
||||
'foo': 'a',
|
||||
}],
|
||||
'b': [{
|
||||
'foo': 'b',
|
||||
}, {
|
||||
'foo': 'b',
|
||||
}],
|
||||
'c': [{
|
||||
'foo': 'c',
|
||||
}, {
|
||||
'foo': 'c',
|
||||
}, {
|
||||
'foo': 'c',
|
||||
}],
|
||||
}
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'testGroupBy', current_value, stored_value)
|
||||
93
ccxt/test/base/test_handle_methods.py
Normal file
93
ccxt/test/base/test_handle_methods.py
Normal file
@@ -0,0 +1,93 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
|
||||
def helper_test_handle_market_type_and_params():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
'options': {
|
||||
'defaultType': 'valueFromOptions',
|
||||
'fetchX': {
|
||||
'defaultType': 'valueFromMethodOptions',
|
||||
},
|
||||
},
|
||||
})
|
||||
initial_params = {
|
||||
'defaultType': 'valueFromParam',
|
||||
}
|
||||
market = exchange.safe_market('TEST1/TEST2')
|
||||
market['type'] = 'spot'
|
||||
#
|
||||
# ########### test different variations ###########
|
||||
#
|
||||
# case #1, should prevail: param
|
||||
#
|
||||
[market_type_1, params1] = exchange.handle_market_type_and_params('fetchX', market, initial_params, 'valueDefault')
|
||||
assert 'defaultType' in initial_params
|
||||
assert not ('defaultType' in params1)
|
||||
assert market_type_1 == 'valueFromParam'
|
||||
#
|
||||
# case #2, should prevail: market.type
|
||||
#
|
||||
[market_type_2, params2] = exchange.handle_market_type_and_params('fetchX', market, {}, 'valueDefault')
|
||||
assert market_type_2 == 'spot'
|
||||
#
|
||||
# case #3, should prevail: valueDefault
|
||||
#
|
||||
[market_type_3, params3] = exchange.handle_market_type_and_params('fetchX', None, {}, 'valueDefault')
|
||||
assert market_type_3 == 'valueDefault'
|
||||
#
|
||||
# case #4, should prevail: method options
|
||||
#
|
||||
[market_type_4, params4] = exchange.handle_market_type_and_params('fetchX', None, {})
|
||||
assert market_type_4 == 'valueFromMethodOptions'
|
||||
#
|
||||
# case #5, should prevail: options
|
||||
#
|
||||
[market_type_5, params5] = exchange.handle_market_type_and_params('fetchY', None, {}, None)
|
||||
assert market_type_5 == 'valueFromOptions'
|
||||
#
|
||||
# case #6, should prevail: spot (because hardcoded in base)
|
||||
#
|
||||
exchange.options['defaultType'] = None
|
||||
[market_type_6, params6] = exchange.handle_market_type_and_params('fetchY', None, {}, None)
|
||||
assert market_type_6 == 'spot'
|
||||
# fake assertion to avoid unused vars
|
||||
assert params1 is not None or params2 is not None or params3 is not None or params4 is not None or params5 is not None or params6 is not None
|
||||
|
||||
|
||||
def helper_test_handle_network_request():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
'options': {
|
||||
'networks': {
|
||||
'XYZ': 'Xyz',
|
||||
},
|
||||
},
|
||||
})
|
||||
exchange.currencies = exchange.create_safe_dictionary() # todo: initialize in C# base files
|
||||
currency_code = 'ETH' # todo: in future with complex cases
|
||||
# no-case
|
||||
[request1, params1] = exchange.handle_request_network({
|
||||
'network': 'XYZ',
|
||||
}, {}, 'chain_id', currency_code, False)
|
||||
assert not ('network' in params1)
|
||||
assert 'chain_id' in request1
|
||||
assert request1['chain_id'] == 'Xyz'
|
||||
|
||||
|
||||
def test_handle_methods():
|
||||
helper_test_handle_market_type_and_params()
|
||||
helper_test_handle_network_request()
|
||||
42
ccxt/test/base/test_json.py
Normal file
42
ccxt/test/base/test_json.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
from ccxt.base.errors import BadRequest # noqa E402
|
||||
|
||||
def test_json():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'regirock',
|
||||
})
|
||||
# Test: object
|
||||
obj = {
|
||||
'k': 'v',
|
||||
}
|
||||
obj_json = exchange.json(obj)
|
||||
assert obj_json == '{"k":"v"}'
|
||||
# Test: list
|
||||
list = [1, 2]
|
||||
list_json = exchange.json(list)
|
||||
assert list_json == '[1,2]'
|
||||
assert 'GO_SKIP_START'
|
||||
try:
|
||||
raise BadRequest('some error')
|
||||
except Exception as e:
|
||||
err_string = exchange.json(e)
|
||||
assert err_string == '{"name":"BadRequest"}'
|
||||
assert 'GO_SKIP_END'
|
||||
# Test: json a string
|
||||
str = 'ccxt, rocks!'
|
||||
serialized_string = exchange.json(str)
|
||||
assert serialized_string == '"ccxt, rocks!"'
|
||||
342
ccxt/test/base/test_number.py
Normal file
342
ccxt/test/base/test_number.py
Normal file
@@ -0,0 +1,342 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.base.decimal_to_precision import DECIMAL_PLACES # noqa E402
|
||||
from ccxt.base.decimal_to_precision import TICK_SIZE # noqa E402
|
||||
from ccxt.base.decimal_to_precision import NO_PADDING # noqa E402
|
||||
from ccxt.base.decimal_to_precision import TRUNCATE # noqa E402
|
||||
from ccxt.base.decimal_to_precision import ROUND # noqa E402
|
||||
from ccxt.base.decimal_to_precision import SIGNIFICANT_DIGITS # noqa E402
|
||||
from ccxt.base.decimal_to_precision import PAD_WITH_ZERO # noqa E402
|
||||
from ccxt.base.decimal_to_precision import decimal_to_precision # noqa E402
|
||||
from ccxt.base.decimal_to_precision import number_to_string # noqa E402
|
||||
import ccxt # noqa: F402
|
||||
from ccxt.base.precise import Precise # noqa E402
|
||||
|
||||
def test_number():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'regirock',
|
||||
})
|
||||
# ----------------------------------------------------------------------------
|
||||
# numberToString
|
||||
assert exchange.number_to_string(-7.8e-7) == '-0.00000078'
|
||||
assert exchange.number_to_string(7.8e-7) == '0.00000078'
|
||||
assert exchange.number_to_string(-0.0000017805) == '-0.0000017805'
|
||||
assert exchange.number_to_string(0.0000017805) == '0.0000017805'
|
||||
assert exchange.number_to_string(-7.0005e+27) == '-7000500000000000000000000000'
|
||||
assert exchange.number_to_string(7.0005e+27) == '7000500000000000000000000000'
|
||||
assert exchange.number_to_string(-7.9e+27) == '-7900000000000000000000000000'
|
||||
assert exchange.number_to_string(7e+27) == '7000000000000000000000000000'
|
||||
assert exchange.number_to_string(7.9e+27) == '7900000000000000000000000000'
|
||||
assert exchange.number_to_string(-12.345) == '-12.345'
|
||||
assert exchange.number_to_string(12.345) == '12.345'
|
||||
assert exchange.number_to_string(0) == '0'
|
||||
assert exchange.number_to_string(7.35946e+21) == '7359460000000000000000'
|
||||
assert exchange.number_to_string(1e-8) == '0.00000001'
|
||||
assert exchange.number_to_string(1e-7) == '0.0000001'
|
||||
assert exchange.number_to_string(-1e-7) == '-0.0000001'
|
||||
# ----------------------------------------------------------------------------
|
||||
# testDecimalToPrecisionTruncationToNDigitsAfterDot
|
||||
assert exchange.decimal_to_precision('12.3456000', TRUNCATE, 100, DECIMAL_PLACES) == '12.3456'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, 100, DECIMAL_PLACES) == '12.3456'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, 4, DECIMAL_PLACES) == '12.3456'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, 3, DECIMAL_PLACES) == '12.345'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, 2, DECIMAL_PLACES) == '12.34'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, 1, DECIMAL_PLACES) == '12.3'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, 0, DECIMAL_PLACES) == '12'
|
||||
# ['12.3456', TRUNCATE, -1, DECIMAL_PLACES, '10'], # not yet supported
|
||||
# ['123.456', TRUNCATE, -2, DECIMAL_PLACES, '120'], # not yet supported
|
||||
# ['123.456', TRUNCATE, -3, DECIMAL_PLACES, '100'], # not yet supported
|
||||
assert exchange.decimal_to_precision('0.0000001', TRUNCATE, 8, DECIMAL_PLACES) == '0.0000001'
|
||||
assert exchange.decimal_to_precision('0.00000001', TRUNCATE, 8, DECIMAL_PLACES) == '0.00000001'
|
||||
assert exchange.decimal_to_precision('0.000000000', TRUNCATE, 9, DECIMAL_PLACES, PAD_WITH_ZERO) == '0.000000000'
|
||||
assert exchange.decimal_to_precision('0.000000001', TRUNCATE, 9, DECIMAL_PLACES, PAD_WITH_ZERO) == '0.000000001'
|
||||
assert exchange.decimal_to_precision('12.3456', TRUNCATE, -1, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('123.456', TRUNCATE, -1, DECIMAL_PLACES) == '120'
|
||||
assert exchange.decimal_to_precision('123.456', TRUNCATE, -2, DECIMAL_PLACES) == '100'
|
||||
assert exchange.decimal_to_precision('9.99999', TRUNCATE, -1, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('99.9999', TRUNCATE, -1, DECIMAL_PLACES) == '90'
|
||||
assert exchange.decimal_to_precision('99.9999', TRUNCATE, -2, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('0', TRUNCATE, 0, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('-0.9', TRUNCATE, 0, DECIMAL_PLACES) == '0'
|
||||
# ----------------------------------------------------------------------------
|
||||
# testDecimalToPrecisionTruncationToNSignificantDigits
|
||||
assert exchange.decimal_to_precision('0.000123456700', TRUNCATE, 100, SIGNIFICANT_DIGITS) == '0.0001234567'
|
||||
assert exchange.decimal_to_precision('0.0001234567', TRUNCATE, 100, SIGNIFICANT_DIGITS) == '0.0001234567'
|
||||
assert exchange.decimal_to_precision('0.0001234567', TRUNCATE, 7, SIGNIFICANT_DIGITS) == '0.0001234567'
|
||||
assert exchange.decimal_to_precision('0.000123456', TRUNCATE, 6, SIGNIFICANT_DIGITS) == '0.000123456'
|
||||
assert exchange.decimal_to_precision('0.000123456', TRUNCATE, 5, SIGNIFICANT_DIGITS) == '0.00012345'
|
||||
assert exchange.decimal_to_precision('0.000123456', TRUNCATE, 2, SIGNIFICANT_DIGITS) == '0.00012'
|
||||
assert exchange.decimal_to_precision('0.000123456', TRUNCATE, 1, SIGNIFICANT_DIGITS) == '0.0001'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 10, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '123.0000987'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 8, SIGNIFICANT_DIGITS) == '123.00009'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 7, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '123.0000'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 6, SIGNIFICANT_DIGITS) == '123'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 5, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '123.00'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 4, SIGNIFICANT_DIGITS) == '123'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 4, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '123.0'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 3, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '123'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 2, SIGNIFICANT_DIGITS) == '120'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 1, SIGNIFICANT_DIGITS) == '100'
|
||||
assert exchange.decimal_to_precision('123.0000987654', TRUNCATE, 1, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '100'
|
||||
assert exchange.decimal_to_precision('1234', TRUNCATE, 5, SIGNIFICANT_DIGITS) == '1234'
|
||||
assert exchange.decimal_to_precision('1234', TRUNCATE, 5, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '1234.0'
|
||||
assert exchange.decimal_to_precision('1234', TRUNCATE, 4, SIGNIFICANT_DIGITS) == '1234'
|
||||
assert exchange.decimal_to_precision('1234', TRUNCATE, 4, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '1234'
|
||||
assert exchange.decimal_to_precision('1234.69', TRUNCATE, 0, SIGNIFICANT_DIGITS) == '0'
|
||||
assert exchange.decimal_to_precision('1234.69', TRUNCATE, 0, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '0'
|
||||
# ----------------------------------------------------------------------------
|
||||
# testDecimalToPrecisionRoundingToNDigitsAfterDot
|
||||
assert exchange.decimal_to_precision('12.3456000', ROUND, 100, DECIMAL_PLACES) == '12.3456'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, 100, DECIMAL_PLACES) == '12.3456'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, 4, DECIMAL_PLACES) == '12.3456'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, 3, DECIMAL_PLACES) == '12.346'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, 2, DECIMAL_PLACES) == '12.35'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, 1, DECIMAL_PLACES) == '12.3'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, 0, DECIMAL_PLACES) == '12'
|
||||
# todo:
|
||||
# ['9.999', ROUND, 3, DECIMAL_PLACES, NO_PADDING, '9.999'],
|
||||
# ['9.999', ROUND, 2, DECIMAL_PLACES, NO_PADDING, '10'],
|
||||
# ['9.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO, '10.00'],
|
||||
# ['99.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO, '100.00'],
|
||||
# ['-99.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO, '-100.00'],
|
||||
# ['12.3456', ROUND, -1, DECIMAL_PLACES, NO_PADDING, '10'], # not yet supported
|
||||
# ['123.456', ROUND, -1, DECIMAL_PLACES, NO_PADDING, '120'], # not yet supported
|
||||
# ['123.456', ROUND, -2, DECIMAL_PLACES, NO_PADDING, '100'], # not yet supported
|
||||
# a problematic case in PHP
|
||||
assert exchange.decimal_to_precision('10000', ROUND, 6, DECIMAL_PLACES) == '10000'
|
||||
assert exchange.decimal_to_precision('0.00003186', ROUND, 8, DECIMAL_PLACES) == '0.00003186'
|
||||
assert exchange.decimal_to_precision('12.3456', ROUND, -1, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('123.456', ROUND, -1, DECIMAL_PLACES) == '120'
|
||||
assert exchange.decimal_to_precision('123.456', ROUND, -2, DECIMAL_PLACES) == '100'
|
||||
assert exchange.decimal_to_precision('9.99999', ROUND, -1, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('99.9999', ROUND, -1, DECIMAL_PLACES) == '100'
|
||||
assert exchange.decimal_to_precision('99.9999', ROUND, -2, DECIMAL_PLACES) == '100'
|
||||
assert exchange.decimal_to_precision('9.999', ROUND, 3, DECIMAL_PLACES) == '9.999'
|
||||
assert exchange.decimal_to_precision('9.999', ROUND, 2, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('9.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO) == '10.00'
|
||||
assert exchange.decimal_to_precision('99.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO) == '100.00'
|
||||
assert exchange.decimal_to_precision('-99.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO) == '-100.00'
|
||||
# ----------------------------------------------------------------------------
|
||||
# testDecimalToPrecisionRoundingToNSignificantDigits
|
||||
assert exchange.decimal_to_precision('0.000123456700', ROUND, 100, SIGNIFICANT_DIGITS) == '0.0001234567'
|
||||
assert exchange.decimal_to_precision('0.0001234567', ROUND, 100, SIGNIFICANT_DIGITS) == '0.0001234567'
|
||||
assert exchange.decimal_to_precision('0.0001234567', ROUND, 7, SIGNIFICANT_DIGITS) == '0.0001234567'
|
||||
assert exchange.decimal_to_precision('0.000123456', ROUND, 6, SIGNIFICANT_DIGITS) == '0.000123456'
|
||||
assert exchange.decimal_to_precision('0.000123456', ROUND, 5, SIGNIFICANT_DIGITS) == '0.00012346'
|
||||
assert exchange.decimal_to_precision('0.000123456', ROUND, 4, SIGNIFICANT_DIGITS) == '0.0001235'
|
||||
assert exchange.decimal_to_precision('0.00012', ROUND, 2, SIGNIFICANT_DIGITS) == '0.00012'
|
||||
assert exchange.decimal_to_precision('0.0001', ROUND, 1, SIGNIFICANT_DIGITS) == '0.0001'
|
||||
assert exchange.decimal_to_precision('123.0000987654', ROUND, 7, SIGNIFICANT_DIGITS) == '123.0001'
|
||||
assert exchange.decimal_to_precision('123.0000987654', ROUND, 6, SIGNIFICANT_DIGITS) == '123'
|
||||
assert exchange.decimal_to_precision('0.00098765', ROUND, 2, SIGNIFICANT_DIGITS) == '0.00099'
|
||||
assert exchange.decimal_to_precision('0.00098765', ROUND, 2, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '0.00099'
|
||||
assert exchange.decimal_to_precision('0.00098765', ROUND, 1, SIGNIFICANT_DIGITS) == '0.001'
|
||||
assert exchange.decimal_to_precision('0.00098765', ROUND, 10, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '0.0009876500000'
|
||||
assert exchange.decimal_to_precision('0.098765', ROUND, 1, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) == '0.1'
|
||||
assert exchange.decimal_to_precision('0', ROUND, 0, SIGNIFICANT_DIGITS) == '0'
|
||||
assert exchange.decimal_to_precision('-0.123', ROUND, 0, SIGNIFICANT_DIGITS) == '0'
|
||||
assert exchange.decimal_to_precision('0.00000044', ROUND, 5, SIGNIFICANT_DIGITS) == '0.00000044'
|
||||
# ----------------------------------------------------------------------------
|
||||
# testDecimalToPrecisionRoundingToTickSize
|
||||
assert exchange.decimal_to_precision('0.000123456700', ROUND, 0.00012, TICK_SIZE) == '0.00012'
|
||||
assert exchange.decimal_to_precision('0.0001234567', ROUND, 0.00013, TICK_SIZE) == '0.00013'
|
||||
assert exchange.decimal_to_precision('0.0001234567', TRUNCATE, 0.00013, TICK_SIZE) == '0'
|
||||
assert exchange.decimal_to_precision('101.000123456700', ROUND, 100, TICK_SIZE) == '100'
|
||||
assert exchange.decimal_to_precision('0.000123456700', ROUND, 100, TICK_SIZE) == '0'
|
||||
assert exchange.decimal_to_precision('165', TRUNCATE, 110, TICK_SIZE) == '110'
|
||||
assert exchange.decimal_to_precision('3210', TRUNCATE, 1110, TICK_SIZE) == '2220'
|
||||
assert exchange.decimal_to_precision('165', ROUND, 110, TICK_SIZE) == '220'
|
||||
assert exchange.decimal_to_precision('0.000123456789', ROUND, 1.2e-7, TICK_SIZE) == '0.00012348'
|
||||
assert exchange.decimal_to_precision('0.000123456789', TRUNCATE, 1.2e-7, TICK_SIZE) == '0.00012336'
|
||||
assert exchange.decimal_to_precision('0.000273398', ROUND, 1e-7, TICK_SIZE) == '0.0002734'
|
||||
assert exchange.decimal_to_precision('0.00005714', TRUNCATE, 1e-8, TICK_SIZE) == '0.00005714'
|
||||
# this line causes problems in JS, fix with Precise
|
||||
# assert (exchange.decimalToPrecision ('0.0000571495257361', TRUNCATE, 0.00000001, TICK_SIZE) === '0.00005714');
|
||||
assert exchange.decimal_to_precision('0.01', ROUND, 0.0001, TICK_SIZE, PAD_WITH_ZERO) == '0.0100'
|
||||
assert exchange.decimal_to_precision('0.01', TRUNCATE, 0.0001, TICK_SIZE, PAD_WITH_ZERO) == '0.0100'
|
||||
assert exchange.decimal_to_precision('-0.000123456789', ROUND, 1.2e-7, TICK_SIZE) == '-0.00012348'
|
||||
assert exchange.decimal_to_precision('-0.000123456789', TRUNCATE, 1.2e-7, TICK_SIZE) == '-0.00012336'
|
||||
assert exchange.decimal_to_precision('-165', TRUNCATE, 110, TICK_SIZE) == '-110'
|
||||
assert exchange.decimal_to_precision('-165', ROUND, 110, TICK_SIZE) == '-220'
|
||||
assert exchange.decimal_to_precision('-1650', TRUNCATE, 1100, TICK_SIZE) == '-1100'
|
||||
assert exchange.decimal_to_precision('-1650', ROUND, 1100, TICK_SIZE) == '-2200'
|
||||
assert exchange.decimal_to_precision('0.0006', TRUNCATE, 0.0001, TICK_SIZE) == '0.0006'
|
||||
assert exchange.decimal_to_precision('-0.0006', TRUNCATE, 0.0001, TICK_SIZE) == '-0.0006'
|
||||
assert exchange.decimal_to_precision('0.6', TRUNCATE, 0.2, TICK_SIZE) == '0.6'
|
||||
assert exchange.decimal_to_precision('-0.6', TRUNCATE, 0.2, TICK_SIZE) == '-0.6'
|
||||
assert exchange.decimal_to_precision('1.2', ROUND, 0.4, TICK_SIZE) == '1.2'
|
||||
assert exchange.decimal_to_precision('-1.2', ROUND, 0.4, TICK_SIZE) == '-1.2'
|
||||
assert exchange.decimal_to_precision('1.2', ROUND, 0.02, TICK_SIZE) == '1.2'
|
||||
assert exchange.decimal_to_precision('-1.2', ROUND, 0.02, TICK_SIZE) == '-1.2'
|
||||
assert exchange.decimal_to_precision('44', ROUND, 4.4, TICK_SIZE) == '44'
|
||||
assert exchange.decimal_to_precision('-44', ROUND, 4.4, TICK_SIZE) == '-44'
|
||||
assert exchange.decimal_to_precision('44.00000001', ROUND, 4.4, TICK_SIZE) == '44'
|
||||
assert exchange.decimal_to_precision('-44.00000001', ROUND, 4.4, TICK_SIZE) == '-44'
|
||||
# https://github.com/ccxt/ccxt/issues/6731
|
||||
assert exchange.decimal_to_precision('20', TRUNCATE, 1e-8, TICK_SIZE) == '20'
|
||||
# ----------------------------------------------------------------------------
|
||||
# testDecimalToPrecisionNegativeNumbers
|
||||
assert exchange.decimal_to_precision('-0.123456', TRUNCATE, 5, DECIMAL_PLACES) == '-0.12345'
|
||||
assert exchange.decimal_to_precision('-0.123456', ROUND, 5, DECIMAL_PLACES) == '-0.12346'
|
||||
# ----------------------------------------------------------------------------
|
||||
# decimalToPrecision: without dot / trailing dot
|
||||
assert exchange.decimal_to_precision('123', TRUNCATE, 0) == '123'
|
||||
assert exchange.decimal_to_precision('123', TRUNCATE, 5, DECIMAL_PLACES) == '123'
|
||||
assert exchange.decimal_to_precision('123', TRUNCATE, 5, DECIMAL_PLACES, PAD_WITH_ZERO) == '123.00000'
|
||||
assert exchange.decimal_to_precision('123.', TRUNCATE, 0, DECIMAL_PLACES) == '123'
|
||||
assert exchange.decimal_to_precision('123.', TRUNCATE, 5, DECIMAL_PLACES, PAD_WITH_ZERO) == '123.00000'
|
||||
assert exchange.decimal_to_precision('0.', TRUNCATE, 0) == '0'
|
||||
assert exchange.decimal_to_precision('0.', TRUNCATE, 5, DECIMAL_PLACES, PAD_WITH_ZERO) == '0.00000'
|
||||
# ----------------------------------------------------------------------------
|
||||
# decimalToPrecision: rounding for equidistant digits
|
||||
assert exchange.decimal_to_precision('1.44', ROUND, 1, DECIMAL_PLACES) == '1.4'
|
||||
assert exchange.decimal_to_precision('1.45', ROUND, 1, DECIMAL_PLACES) == '1.5'
|
||||
assert exchange.decimal_to_precision('1.45', ROUND, 0, DECIMAL_PLACES) == '1' # not 2
|
||||
# ----------------------------------------------------------------------------
|
||||
# negative precision only implemented so far in python
|
||||
# pretty useless for decimal applications as anything |x| < 5 === 0
|
||||
# NO_PADDING and PAD_WITH_ZERO are ignored
|
||||
assert exchange.decimal_to_precision('5', ROUND, -1, DECIMAL_PLACES) == '10'
|
||||
assert exchange.decimal_to_precision('4.999', ROUND, -1, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('0.0431531423', ROUND, -1, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('-69.3', ROUND, -1, DECIMAL_PLACES) == '-70'
|
||||
assert exchange.decimal_to_precision('5001', ROUND, -4, DECIMAL_PLACES) == '10000'
|
||||
assert exchange.decimal_to_precision('4999.999', ROUND, -4, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('69.3', TRUNCATE, -2, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('-69.3', TRUNCATE, -2, DECIMAL_PLACES) == '0'
|
||||
assert exchange.decimal_to_precision('69.3', TRUNCATE, -1, SIGNIFICANT_DIGITS) == '60'
|
||||
assert exchange.decimal_to_precision('-69.3', TRUNCATE, -1, SIGNIFICANT_DIGITS) == '-60'
|
||||
assert exchange.decimal_to_precision('69.3', TRUNCATE, -2, SIGNIFICANT_DIGITS) == '0'
|
||||
assert exchange.decimal_to_precision('1602000000000000000000', TRUNCATE, 3, SIGNIFICANT_DIGITS) == '1600000000000000000000'
|
||||
# ----------------------------------------------------------------------------
|
||||
# decimal_to_precision: stringified precision
|
||||
assert exchange.decimal_to_precision('-0.000123456789', ROUND, '0.00000012', TICK_SIZE) == '-0.00012348'
|
||||
assert exchange.decimal_to_precision('-0.000123456789', TRUNCATE, '0.00000012', TICK_SIZE) == '-0.00012336'
|
||||
assert exchange.decimal_to_precision('-165', TRUNCATE, '110', TICK_SIZE) == '-110'
|
||||
assert exchange.decimal_to_precision('-165', ROUND, '110', TICK_SIZE) == '-220'
|
||||
# ----------------------------------------------------------------------------
|
||||
# testDecimalToPrecisionErrorHandling (todo)
|
||||
#
|
||||
# throws (() =>
|
||||
# decimalToPrecision ('123456.789', TRUNCATE, -2, DECIMAL_PLACES),
|
||||
# 'negative precision is not yet supported')
|
||||
#
|
||||
# throws (() =>
|
||||
# decimalToPrecision ('foo'),
|
||||
# "invalid number (contains an illegal character 'f')")
|
||||
#
|
||||
# throws (() =>
|
||||
# decimalToPrecision ('0.01', TRUNCATE, -1, TICK_SIZE),
|
||||
# "TICK_SIZE cant be used with negative numPrecisionDigits")
|
||||
# ----------------------------------------------------------------------------
|
||||
w = '-1.123e-6'
|
||||
x = '0.00000002'
|
||||
y = '69696900000'
|
||||
z = '0'
|
||||
a = '1e8'
|
||||
assert Precise.string_mul(x, y) == '1393.938'
|
||||
assert Precise.string_mul(y, x) == '1393.938'
|
||||
assert Precise.string_add(x, y) == '69696900000.00000002'
|
||||
assert Precise.string_add(y, x) == '69696900000.00000002'
|
||||
assert Precise.string_sub(x, y) == '-69696899999.99999998'
|
||||
assert Precise.string_sub(y, x) == '69696899999.99999998'
|
||||
assert Precise.string_div(x, y, 1) == '0'
|
||||
assert Precise.string_div(x, y) == '0'
|
||||
assert Precise.string_div(x, y, 19) == '0.0000000000000000002'
|
||||
assert Precise.string_div(x, y, 20) == '0.00000000000000000028'
|
||||
assert Precise.string_div(x, y, 21) == '0.000000000000000000286'
|
||||
assert Precise.string_div(x, y, 22) == '0.0000000000000000002869'
|
||||
assert Precise.string_div(y, x) == '3484845000000000000'
|
||||
assert Precise.string_mul(x, w) == '-0.00000000000002246'
|
||||
assert Precise.string_mul(w, x) == '-0.00000000000002246'
|
||||
assert Precise.string_add(x, w) == '-0.000001103'
|
||||
assert Precise.string_add(w, x) == '-0.000001103'
|
||||
assert Precise.string_sub(x, w) == '0.000001143'
|
||||
assert Precise.string_sub(w, x) == '-0.000001143'
|
||||
assert Precise.string_div(x, w) == '-0.017809439002671415'
|
||||
assert Precise.string_div(w, x) == '-56.15'
|
||||
assert Precise.string_mul(z, w) == '0'
|
||||
assert Precise.string_mul(z, x) == '0'
|
||||
assert Precise.string_mul(z, y) == '0'
|
||||
assert Precise.string_mul(w, z) == '0'
|
||||
assert Precise.string_mul(x, z) == '0'
|
||||
assert Precise.string_mul(y, z) == '0'
|
||||
assert Precise.string_add(z, w) == '-0.000001123'
|
||||
assert Precise.string_add(z, x) == '0.00000002'
|
||||
assert Precise.string_add(z, y) == '69696900000'
|
||||
assert Precise.string_add(w, z) == '-0.000001123'
|
||||
assert Precise.string_add(x, z) == '0.00000002'
|
||||
assert Precise.string_add(y, z) == '69696900000'
|
||||
assert Precise.string_mul(x, a) == '2'
|
||||
assert Precise.string_mul(a, x) == '2'
|
||||
assert Precise.string_mul(y, a) == '6969690000000000000'
|
||||
assert Precise.string_mul(a, y) == '6969690000000000000'
|
||||
assert Precise.string_div(y, a) == '696.969'
|
||||
assert Precise.string_div(y, a, -1) == '690'
|
||||
assert Precise.string_div(y, a, 0) == '696'
|
||||
assert Precise.string_div(y, a, 1) == '696.9'
|
||||
assert Precise.string_div(y, a, 2) == '696.96'
|
||||
assert Precise.string_div(a, y) == '0.001434784043479695'
|
||||
assert Precise.string_abs('0') == '0'
|
||||
assert Precise.string_abs('-0') == '0'
|
||||
assert Precise.string_abs('-500.1') == '500.1'
|
||||
assert Precise.string_abs('213') == '213'
|
||||
assert Precise.string_neg('0') == '0'
|
||||
assert Precise.string_neg('-0') == '0'
|
||||
assert Precise.string_neg('-500.1') == '500.1'
|
||||
assert Precise.string_neg('213') == '-213'
|
||||
assert Precise.string_mod('57.123', '10') == '7.123'
|
||||
assert Precise.string_mod('18', '6') == '0'
|
||||
assert Precise.string_mod('10.1', '0.5') == '0.1'
|
||||
assert Precise.string_mod('10000000', '5555') == '1000'
|
||||
assert Precise.string_mod('5550', '120') == '30'
|
||||
assert Precise.string_equals('1.0000', '1')
|
||||
assert Precise.string_equals('-0.0', '0')
|
||||
assert Precise.string_equals('-0.0', '0.0')
|
||||
assert Precise.string_equals('5.534000', '5.5340')
|
||||
assert Precise.string_min('1.0000', '2') == '1'
|
||||
assert Precise.string_min('2', '1.2345') == '1.2345'
|
||||
assert Precise.string_min('3.1415', '-2') == '-2'
|
||||
assert Precise.string_min('-3.1415', '-2') == '-3.1415'
|
||||
assert Precise.string_min('0.000', '-0.0') == '0'
|
||||
assert Precise.string_max('1.0000', '2') == '2'
|
||||
assert Precise.string_max('2', '1.2345') == '2'
|
||||
assert Precise.string_max('3.1415', '-2') == '3.1415'
|
||||
assert Precise.string_max('-3.1415', '-2') == '-2'
|
||||
assert Precise.string_max('0.000', '-0.0') == '0'
|
||||
assert not Precise.string_gt('1.0000', '2')
|
||||
assert Precise.string_gt('2', '1.2345')
|
||||
assert Precise.string_gt('3.1415', '-2')
|
||||
assert not Precise.string_gt('-3.1415', '-2')
|
||||
assert not Precise.string_gt('3.1415', '3.1415')
|
||||
assert Precise.string_gt('3.14150000000000000000001', '3.1415')
|
||||
assert not Precise.string_ge('1.0000', '2')
|
||||
assert Precise.string_ge('2', '1.2345')
|
||||
assert Precise.string_ge('3.1415', '-2')
|
||||
assert not Precise.string_ge('-3.1415', '-2')
|
||||
assert Precise.string_ge('3.1415', '3.1415')
|
||||
assert Precise.string_ge('3.14150000000000000000001', '3.1415')
|
||||
assert Precise.string_lt('1.0000', '2')
|
||||
assert not Precise.string_lt('2', '1.2345')
|
||||
assert not Precise.string_lt('3.1415', '-2')
|
||||
assert Precise.string_lt('-3.1415', '-2')
|
||||
assert not Precise.string_lt('3.1415', '3.1415')
|
||||
assert Precise.string_lt('3.1415', '3.14150000000000000000001')
|
||||
assert Precise.string_le('1.0000', '2')
|
||||
assert not Precise.string_le('2', '1.2345')
|
||||
assert not Precise.string_le('3.1415', '-2')
|
||||
assert Precise.string_le('-3.1415', '-2')
|
||||
assert Precise.string_le('3.1415', '3.1415')
|
||||
assert Precise.string_le('3.1415', '3.14150000000000000000001')
|
||||
39
ccxt/test/base/test_number_to_string.py
Normal file
39
ccxt/test/base/test_number_to_string.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.base.decimal_to_precision import number_to_string # noqa E402
|
||||
import ccxt # noqa: F402
|
||||
|
||||
def test_number_to_string():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'regirock',
|
||||
})
|
||||
# ----------------------------------------------------------------------------
|
||||
# numberToString
|
||||
assert exchange.number_to_string(-7.8e-7) == '-0.00000078'
|
||||
assert exchange.number_to_string(7.8e-7) == '0.00000078'
|
||||
assert exchange.number_to_string(-0.0000017805) == '-0.0000017805'
|
||||
assert exchange.number_to_string(0.0000017805) == '0.0000017805'
|
||||
assert exchange.number_to_string(-7.0005e+27) == '-7000500000000000000000000000'
|
||||
assert exchange.number_to_string(7.0005e+27) == '7000500000000000000000000000'
|
||||
assert exchange.number_to_string(-7.9e+27) == '-7900000000000000000000000000'
|
||||
assert exchange.number_to_string(7e+27) == '7000000000000000000000000000'
|
||||
assert exchange.number_to_string(7.9e+27) == '7900000000000000000000000000'
|
||||
assert exchange.number_to_string(-12.345) == '-12.345'
|
||||
assert exchange.number_to_string(12.345) == '12.345'
|
||||
assert exchange.number_to_string(0) == '0'
|
||||
assert exchange.number_to_string(7.35946e+21) == '7359460000000000000000'
|
||||
assert exchange.number_to_string(1e-8) == '0.00000001'
|
||||
assert exchange.number_to_string(1e-7) == '0.0000001'
|
||||
assert exchange.number_to_string(-1e-7) == '-0.0000001'
|
||||
37
ccxt/test/base/test_omit.py
Normal file
37
ccxt/test/base/test_omit.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
def test_omit():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
})
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'testOmit', exchange.omit({}, 'foo'), {})
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'testOmit', exchange.omit({
|
||||
'foo': 2,
|
||||
}, 'foo'), {})
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'testOmit', exchange.omit({
|
||||
'foo': 2,
|
||||
'bar': 3,
|
||||
}, 'foo'), {
|
||||
'bar': 3,
|
||||
})
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'testOmit', exchange.omit({
|
||||
'foo': 2,
|
||||
'bar': 3,
|
||||
}, ['foo']), {
|
||||
'bar': 3,
|
||||
})
|
||||
24
ccxt/test/base/test_parse_precision.py
Normal file
24
ccxt/test/base/test_parse_precision.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
|
||||
def test_parse_precision():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
})
|
||||
assert exchange.parse_precision('15') == '0.000000000000001'
|
||||
assert exchange.parse_precision('1') == '0.1'
|
||||
assert exchange.parse_precision('0') == '1'
|
||||
assert exchange.parse_precision('-5') == '100000'
|
||||
116
ccxt/test/base/test_precise.py
Normal file
116
ccxt/test/base/test_precise.py
Normal file
@@ -0,0 +1,116 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.base.precise import Precise # noqa E402
|
||||
|
||||
def test_precise():
|
||||
w = '-1.123e-6'
|
||||
x = '0.00000002'
|
||||
y = '69696900000'
|
||||
z = '0'
|
||||
a = '1e8'
|
||||
assert Precise.string_mul(x, y) == '1393.938'
|
||||
assert Precise.string_mul(y, x) == '1393.938'
|
||||
assert Precise.string_add(x, y) == '69696900000.00000002'
|
||||
assert Precise.string_add(y, x) == '69696900000.00000002'
|
||||
assert Precise.string_sub(x, y) == '-69696899999.99999998'
|
||||
assert Precise.string_sub(y, x) == '69696899999.99999998'
|
||||
assert Precise.string_div(x, y, 1) == '0'
|
||||
assert Precise.string_div(x, y) == '0'
|
||||
assert Precise.string_div(x, y, 19) == '0.0000000000000000002'
|
||||
assert Precise.string_div(x, y, 20) == '0.00000000000000000028'
|
||||
assert Precise.string_div(x, y, 21) == '0.000000000000000000286'
|
||||
assert Precise.string_div(x, y, 22) == '0.0000000000000000002869'
|
||||
assert Precise.string_div(y, x) == '3484845000000000000'
|
||||
assert Precise.string_mul(x, w) == '-0.00000000000002246'
|
||||
assert Precise.string_mul(w, x) == '-0.00000000000002246'
|
||||
assert Precise.string_add(x, w) == '-0.000001103'
|
||||
assert Precise.string_add(w, x) == '-0.000001103'
|
||||
assert Precise.string_sub(x, w) == '0.000001143'
|
||||
assert Precise.string_sub(w, x) == '-0.000001143'
|
||||
assert Precise.string_div(x, w) == '-0.017809439002671415'
|
||||
assert Precise.string_div(w, x) == '-56.15'
|
||||
assert Precise.string_mul(z, w) == '0'
|
||||
assert Precise.string_mul(z, x) == '0'
|
||||
assert Precise.string_mul(z, y) == '0'
|
||||
assert Precise.string_mul(w, z) == '0'
|
||||
assert Precise.string_mul(x, z) == '0'
|
||||
assert Precise.string_mul(y, z) == '0'
|
||||
assert Precise.string_add(z, w) == '-0.000001123'
|
||||
assert Precise.string_add(z, x) == '0.00000002'
|
||||
assert Precise.string_add(z, y) == '69696900000'
|
||||
assert Precise.string_add(w, z) == '-0.000001123'
|
||||
assert Precise.string_add(x, z) == '0.00000002'
|
||||
assert Precise.string_add(y, z) == '69696900000'
|
||||
assert Precise.string_mul(x, a) == '2'
|
||||
assert Precise.string_mul(a, x) == '2'
|
||||
assert Precise.string_mul(y, a) == '6969690000000000000'
|
||||
assert Precise.string_mul(a, y) == '6969690000000000000'
|
||||
assert Precise.string_div(y, a) == '696.969'
|
||||
assert Precise.string_div(y, a, -1) == '690'
|
||||
assert Precise.string_div(y, a, 0) == '696'
|
||||
assert Precise.string_div(y, a, 1) == '696.9'
|
||||
assert Precise.string_div(y, a, 2) == '696.96'
|
||||
assert Precise.string_div(a, y) == '0.001434784043479695'
|
||||
assert Precise.string_abs('0') == '0'
|
||||
assert Precise.string_abs('-0') == '0'
|
||||
assert Precise.string_abs('-500.1') == '500.1'
|
||||
assert Precise.string_abs('213') == '213'
|
||||
assert Precise.string_neg('0') == '0'
|
||||
assert Precise.string_neg('-0') == '0'
|
||||
assert Precise.string_neg('-500.1') == '500.1'
|
||||
assert Precise.string_neg('213') == '-213'
|
||||
assert Precise.string_mod('57.123', '10') == '7.123'
|
||||
assert Precise.string_mod('18', '6') == '0'
|
||||
assert Precise.string_mod('10.1', '0.5') == '0.1'
|
||||
assert Precise.string_mod('10000000', '5555') == '1000'
|
||||
assert Precise.string_mod('5550', '120') == '30'
|
||||
assert Precise.string_equals('1.0000', '1')
|
||||
assert Precise.string_equals('-0.0', '0')
|
||||
assert Precise.string_equals('-0.0', '0.0')
|
||||
assert Precise.string_equals('5.534000', '5.5340')
|
||||
assert Precise.string_min('1.0000', '2') == '1'
|
||||
assert Precise.string_min('2', '1.2345') == '1.2345'
|
||||
assert Precise.string_min('3.1415', '-2') == '-2'
|
||||
assert Precise.string_min('-3.1415', '-2') == '-3.1415'
|
||||
assert Precise.string_min('0.000', '-0.0') == '0'
|
||||
assert Precise.string_max('1.0000', '2') == '2'
|
||||
assert Precise.string_max('2', '1.2345') == '2'
|
||||
assert Precise.string_max('3.1415', '-2') == '3.1415'
|
||||
assert Precise.string_max('-3.1415', '-2') == '-2'
|
||||
assert Precise.string_max('0.000', '-0.0') == '0'
|
||||
assert not Precise.string_gt('1.0000', '2')
|
||||
assert Precise.string_gt('2', '1.2345')
|
||||
assert Precise.string_gt('3.1415', '-2')
|
||||
assert not Precise.string_gt('-3.1415', '-2')
|
||||
assert not Precise.string_gt('3.1415', '3.1415')
|
||||
assert Precise.string_gt('3.14150000000000000000001', '3.1415')
|
||||
assert not Precise.string_ge('1.0000', '2')
|
||||
assert Precise.string_ge('2', '1.2345')
|
||||
assert Precise.string_ge('3.1415', '-2')
|
||||
assert not Precise.string_ge('-3.1415', '-2')
|
||||
assert Precise.string_ge('3.1415', '3.1415')
|
||||
assert Precise.string_ge('3.14150000000000000000001', '3.1415')
|
||||
assert Precise.string_lt('1.0000', '2')
|
||||
assert not Precise.string_lt('2', '1.2345')
|
||||
assert not Precise.string_lt('3.1415', '-2')
|
||||
assert Precise.string_lt('-3.1415', '-2')
|
||||
assert not Precise.string_lt('3.1415', '3.1415')
|
||||
assert Precise.string_lt('3.1415', '3.14150000000000000000001')
|
||||
assert Precise.string_le('1.0000', '2')
|
||||
assert not Precise.string_le('2', '1.2345')
|
||||
assert not Precise.string_le('3.1415', '-2')
|
||||
assert Precise.string_le('-3.1415', '-2')
|
||||
assert Precise.string_le('3.1415', '3.1415')
|
||||
assert Precise.string_le('3.1415', '3.14150000000000000000001')
|
||||
74
ccxt/test/base/test_remove_repeated_elements_from_array.py
Normal file
74
ccxt/test/base/test_remove_repeated_elements_from_array.py
Normal file
@@ -0,0 +1,74 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
|
||||
def test_remove_repeated_elements_from_array():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
})
|
||||
# CASE 1: by id
|
||||
array1 = [{
|
||||
'id': 'a',
|
||||
'timestamp': 1,
|
||||
'uniq': 'x1',
|
||||
}, {
|
||||
'id': 'b',
|
||||
'timestamp': 2,
|
||||
'uniq': 'x2',
|
||||
}, {
|
||||
'id': 'a',
|
||||
'timestamp': 3,
|
||||
'uniq': 'x3',
|
||||
}, {
|
||||
'id': 'c',
|
||||
'timestamp': 1,
|
||||
'uniq': 'x4',
|
||||
}]
|
||||
res1 = exchange.remove_repeated_elements_from_array(array1, False)
|
||||
res1_length = len(res1)
|
||||
assert res1_length == 3
|
||||
assert res1[0]['uniq'] == 'x1'
|
||||
assert res1[1]['uniq'] == 'x2'
|
||||
assert res1[2]['uniq'] == 'x4'
|
||||
# CASE 2: by timestamp
|
||||
array2 = [{
|
||||
'id': None,
|
||||
'timestamp': 1,
|
||||
'uniq': 'x1',
|
||||
}, {
|
||||
'id': None,
|
||||
'timestamp': 2,
|
||||
'uniq': 'x2',
|
||||
}, {
|
||||
'id': None,
|
||||
'timestamp': 1,
|
||||
'uniq': 'x3',
|
||||
}, {
|
||||
'id': None,
|
||||
'timestamp': 3,
|
||||
'uniq': 'x4',
|
||||
}]
|
||||
res2 = exchange.remove_repeated_elements_from_array(array2, True)
|
||||
res2_length = len(res2)
|
||||
assert res2_length == 3
|
||||
assert res2[0]['uniq'] == 'x1'
|
||||
assert res2[1]['uniq'] == 'x2'
|
||||
assert res2[2]['uniq'] == 'x4'
|
||||
# CASE 3: by timestamp index (used in ohlcv)
|
||||
array3 = [[555, 1, 1, 'x1'], [666, 1, 1, 'x2'], [555, 1, 1, 'x3']]
|
||||
res3 = exchange.remove_repeated_elements_from_array(array3, True)
|
||||
assert len(res3) == 2
|
||||
assert res3[0][3] == 'x1'
|
||||
assert res3[1][3] == 'x2'
|
||||
275
ccxt/test/base/test_safe_methods.py
Normal file
275
ccxt/test/base/test_safe_methods.py
Normal file
@@ -0,0 +1,275 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
|
||||
def equals(a, b):
|
||||
return a == b
|
||||
|
||||
def test_safe_methods():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'regirock',
|
||||
})
|
||||
input_dict = {
|
||||
'i': 1,
|
||||
'f': 0.123,
|
||||
'bool': True,
|
||||
'list': [1, 2, 3],
|
||||
'dict': {
|
||||
'a': 1,
|
||||
},
|
||||
'str': 'heLlo',
|
||||
'strNumber': '3',
|
||||
'zeroNumeric': 0,
|
||||
'zeroString': '0',
|
||||
'undefined': None,
|
||||
'emptyString': '',
|
||||
'floatNumeric': 0.123,
|
||||
'floatString': '0.123',
|
||||
}
|
||||
input_list = ['Hi', 2]
|
||||
compare_dict = {
|
||||
'a': 1,
|
||||
}
|
||||
compare_list = [1, 2, 3]
|
||||
factor = 10
|
||||
# safeValue
|
||||
assert exchange.safe_value(input_dict, 'i') == 1
|
||||
assert exchange.safe_value(input_dict, 'f') == 0.123
|
||||
assert exchange.safe_value(input_dict, 'bool')
|
||||
assert equals(exchange.safe_value(input_dict, 'list'), compare_list)
|
||||
dict_object = exchange.safe_value(input_dict, 'dict')
|
||||
assert equals(dict_object, compare_dict)
|
||||
assert exchange.safe_value(input_dict, 'str') == 'heLlo'
|
||||
assert exchange.safe_value(input_dict, 'strNumber') == '3'
|
||||
assert exchange.safe_value(input_list, 0) == 'Hi'
|
||||
# safeValue2
|
||||
assert exchange.safe_value_2(input_dict, 'a', 'i') == 1
|
||||
assert exchange.safe_value_2(input_dict, 'a', 'f') == 0.123
|
||||
assert exchange.safe_value_2(input_dict, 'a', 'bool')
|
||||
assert equals(exchange.safe_value_2(input_dict, 'a', 'list'), compare_list)
|
||||
dict_object = exchange.safe_value_2(input_dict, 'a', 'dict')
|
||||
assert equals(dict_object, compare_dict)
|
||||
assert exchange.safe_value_2(input_dict, 'a', 'str') == 'heLlo'
|
||||
assert exchange.safe_value_2(input_dict, 'a', 'strNumber') == '3'
|
||||
assert exchange.safe_value_2(input_list, 2, 0) == 'Hi'
|
||||
# safeValueN
|
||||
assert exchange.safe_value_n(input_dict, ['a', 'b', 'i']) == 1
|
||||
assert exchange.safe_value_n(input_dict, ['a', 'b', 'f']) == 0.123
|
||||
assert exchange.safe_value_n(input_dict, ['a', 'b', 'bool'])
|
||||
assert equals(exchange.safe_value_n(input_dict, ['a', 'b', 'list']), compare_list)
|
||||
dict_object = exchange.safe_value_n(input_dict, ['a', 'b', 'dict'])
|
||||
assert equals(dict_object, compare_dict)
|
||||
assert exchange.safe_value_n(input_dict, ['a', 'b', 'str']) == 'heLlo'
|
||||
assert exchange.safe_value_n(input_dict, ['a', 'b', 'strNumber']) == '3'
|
||||
assert exchange.safe_value_n(input_list, [3, 2, 0]) == 'Hi'
|
||||
# safeDict
|
||||
dict_object = exchange.safe_dict(input_dict, 'dict')
|
||||
assert equals(dict_object, compare_dict)
|
||||
list_object = exchange.safe_dict(input_dict, 'list')
|
||||
assert list_object is None
|
||||
assert exchange.safe_dict(input_list, 1) is None
|
||||
# safeDict2
|
||||
dict_object = exchange.safe_dict_2(input_dict, 'a', 'dict')
|
||||
assert equals(dict_object, compare_dict)
|
||||
list_object = exchange.safe_dict_2(input_dict, 'a', 'list')
|
||||
assert list_object is None
|
||||
# @ts-expect-error
|
||||
assert exchange.safe_dict_2(input_list, 2, 1) is None
|
||||
# safeDictN
|
||||
dict_object = exchange.safe_dict_n(input_dict, ['a', 'b', 'dict'])
|
||||
assert equals(dict_object, compare_dict)
|
||||
list_object = exchange.safe_dict_n(input_dict, ['a', 'b', 'list'])
|
||||
assert list_object is None
|
||||
assert exchange.safe_dict_n(input_list, [3, 2, 1]) is None
|
||||
# safeList
|
||||
list_object = exchange.safe_list(input_dict, 'list')
|
||||
assert equals(dict_object, compare_dict)
|
||||
assert exchange.safe_list(input_dict, 'dict') is None
|
||||
assert exchange.safe_list(input_list, 1) is None
|
||||
# safeList2
|
||||
list_object = exchange.safe_list_2(input_dict, 'a', 'list')
|
||||
assert equals(dict_object, compare_dict)
|
||||
assert exchange.safe_list_2(input_dict, 'a', 'dict') is None
|
||||
# @ts-expect-error
|
||||
assert exchange.safe_list_2(input_list, 2, 1) is None
|
||||
# safeListN
|
||||
list_object = exchange.safe_list_n(input_dict, ['a', 'b', 'list'])
|
||||
assert equals(dict_object, compare_dict)
|
||||
assert exchange.safe_list_n(input_dict, ['a', 'b', 'dict']) is None
|
||||
assert exchange.safe_list_n(input_list, [3, 2, 1]) is None
|
||||
# safeString
|
||||
assert exchange.safe_string(input_dict, 'i') == '1'
|
||||
assert exchange.safe_string(input_dict, 'f') == '0.123'
|
||||
# assert (exchange.safeString (inputDict, 'bool') === 'true'); returns True in python and 'true' in js
|
||||
assert exchange.safe_string(input_dict, 'str') == 'heLlo'
|
||||
assert exchange.safe_string(input_dict, 'strNumber') == '3'
|
||||
assert exchange.safe_string(input_list, 0) == 'Hi'
|
||||
# safeString2
|
||||
assert exchange.safe_string_2(input_dict, 'a', 'i') == '1'
|
||||
assert exchange.safe_string_2(input_dict, 'a', 'f') == '0.123'
|
||||
assert exchange.safe_string_2(input_dict, 'a', 'str') == 'heLlo'
|
||||
assert exchange.safe_string_2(input_dict, 'a', 'strNumber') == '3'
|
||||
assert exchange.safe_string_2(input_list, 2, 0) == 'Hi'
|
||||
# safeStringN
|
||||
assert exchange.safe_string_n(input_dict, ['a', 'b', 'i']) == '1'
|
||||
assert exchange.safe_string_n(input_dict, ['a', 'b', 'f']) == '0.123'
|
||||
assert exchange.safe_string_n(input_dict, ['a', 'b', 'str']) == 'heLlo'
|
||||
assert exchange.safe_string_n(input_dict, ['a', 'b', 'strNumber']) == '3'
|
||||
assert exchange.safe_string_n(input_list, [3, 2, 0]) == 'Hi'
|
||||
# safeStringLower
|
||||
assert exchange.safe_string_lower(input_dict, 'i') == '1'
|
||||
assert exchange.safe_string_lower(input_dict, 'f') == '0.123'
|
||||
assert exchange.safe_string_lower(input_dict, 'str') == 'hello'
|
||||
assert exchange.safe_string_lower(input_dict, 'strNumber') == '3'
|
||||
assert exchange.safe_string_lower(input_list, 0) == 'hi'
|
||||
# safeStringLower2
|
||||
assert exchange.safe_string_lower_2(input_dict, 'a', 'i') == '1'
|
||||
assert exchange.safe_string_lower_2(input_dict, 'a', 'f') == '0.123'
|
||||
assert exchange.safe_string_lower_2(input_dict, 'a', 'str') == 'hello'
|
||||
assert exchange.safe_string_lower_2(input_dict, 'a', 'strNumber') == '3'
|
||||
assert exchange.safe_string_lower_2(input_list, 2, 0) == 'hi'
|
||||
# safeStringLowerN
|
||||
assert exchange.safe_string_lower_n(input_dict, ['a', 'b', 'i']) == '1'
|
||||
assert exchange.safe_string_lower_n(input_dict, ['a', 'b', 'f']) == '0.123'
|
||||
assert exchange.safe_string_lower_n(input_dict, ['a', 'b', 'str']) == 'hello'
|
||||
assert exchange.safe_string_lower_n(input_dict, ['a', 'b', 'strNumber']) == '3'
|
||||
assert exchange.safe_string_lower_n(input_list, [3, 2, 0]) == 'hi'
|
||||
# safeStringUpper
|
||||
assert exchange.safe_string_upper(input_dict, 'i') == '1'
|
||||
assert exchange.safe_string_upper(input_dict, 'f') == '0.123'
|
||||
assert exchange.safe_string_upper(input_dict, 'str') == 'HELLO'
|
||||
assert exchange.safe_string_upper(input_dict, 'strNumber') == '3'
|
||||
assert exchange.safe_string_upper(input_list, 0) == 'HI'
|
||||
# safeStringUpper2
|
||||
assert exchange.safe_string_upper_2(input_dict, 'a', 'i') == '1'
|
||||
assert exchange.safe_string_upper_2(input_dict, 'a', 'f') == '0.123'
|
||||
assert exchange.safe_string_upper_2(input_dict, 'a', 'str') == 'HELLO'
|
||||
assert exchange.safe_string_upper_2(input_dict, 'a', 'strNumber') == '3'
|
||||
assert exchange.safe_string_upper_2(input_list, 2, 0) == 'HI'
|
||||
# safeStringUpperN
|
||||
assert exchange.safe_string_upper_n(input_dict, ['a', 'b', 'i']) == '1'
|
||||
assert exchange.safe_string_upper_n(input_dict, ['a', 'b', 'f']) == '0.123'
|
||||
assert exchange.safe_string_upper_n(input_dict, ['a', 'b', 'str']) == 'HELLO'
|
||||
assert exchange.safe_string_upper_n(input_dict, ['a', 'b', 'strNumber']) == '3'
|
||||
assert exchange.safe_string_upper_n(input_list, [3, 2, 0]) == 'HI'
|
||||
# safeInteger
|
||||
assert exchange.safe_integer(input_dict, 'i') == 1
|
||||
assert exchange.safe_integer(input_dict, 'f') == 0
|
||||
assert exchange.safe_integer(input_dict, 'strNumber') == 3
|
||||
assert exchange.safe_integer(input_list, 1) == 2
|
||||
# safeInteger2
|
||||
assert exchange.safe_integer_2(input_dict, 'a', 'i') == 1
|
||||
assert exchange.safe_integer_2(input_dict, 'a', 'f') == 0
|
||||
assert exchange.safe_integer_2(input_dict, 'a', 'strNumber') == 3
|
||||
assert exchange.safe_integer_2(input_list, 2, 1) == 2
|
||||
# safeIntegerN
|
||||
assert exchange.safe_integer_n(input_dict, ['a', 'b', 'i']) == 1
|
||||
assert exchange.safe_integer_n(input_dict, ['a', 'b', 'f']) == 0
|
||||
assert exchange.safe_integer_n(input_dict, ['a', 'b', 'strNumber']) == 3
|
||||
assert exchange.safe_integer_n(input_list, [3, 2, 1]) == 2
|
||||
# safeIntegerOmitZero
|
||||
assert exchange.safe_integer_omit_zero(input_dict, 'i') == 1
|
||||
assert exchange.safe_integer_omit_zero(input_dict, 'f') is None
|
||||
assert exchange.safe_integer_omit_zero(input_dict, 'strNumber') == 3
|
||||
assert exchange.safe_integer_omit_zero(input_list, 1) == 2
|
||||
# safeIntegerProduct
|
||||
assert exchange.safe_integer_product(input_dict, 'i', factor) == 10
|
||||
assert exchange.safe_integer_product(input_dict, 'f', factor) == 1 # NB the result is 1
|
||||
assert exchange.safe_integer_product(input_dict, 'strNumber', factor) == 30
|
||||
assert exchange.safe_integer_product(input_list, 1, factor) == 20
|
||||
# safeIntegerProduct2
|
||||
assert exchange.safe_integer_product_2(input_dict, 'a', 'i', factor) == 10
|
||||
assert exchange.safe_integer_product_2(input_dict, 'a', 'f', factor) == 1 # NB the result is 1
|
||||
assert exchange.safe_integer_product_2(input_dict, 'a', 'strNumber', factor) == 30
|
||||
assert exchange.safe_integer_product_2(input_list, 2, 1, factor) == 20
|
||||
# safeIntegerProductN
|
||||
assert exchange.safe_integer_product_n(input_dict, ['a', 'b', 'i'], factor) == 10
|
||||
assert exchange.safe_integer_product_n(input_dict, ['a', 'b', 'f'], factor) == 1 # NB the result is 1
|
||||
assert exchange.safe_integer_product_n(input_dict, ['a', 'b', 'strNumber'], factor) == 30
|
||||
assert exchange.safe_integer_product_n(input_list, [3, 2, 1], factor) == 20
|
||||
# safeTimestamp
|
||||
assert exchange.safe_timestamp(input_dict, 'i') == 1000
|
||||
assert exchange.safe_timestamp(input_dict, 'f') == 123
|
||||
assert exchange.safe_timestamp(input_dict, 'strNumber') == 3000
|
||||
assert exchange.safe_timestamp(input_list, 1) == 2000
|
||||
# safeTimestamp2
|
||||
assert exchange.safe_timestamp_2(input_dict, 'a', 'i') == 1000
|
||||
assert exchange.safe_timestamp_2(input_dict, 'a', 'f') == 123
|
||||
assert exchange.safe_timestamp_2(input_dict, 'a', 'strNumber') == 3000
|
||||
assert exchange.safe_timestamp_2(input_list, 2, 1) == 2000
|
||||
# safeTimestampN
|
||||
assert exchange.safe_timestamp_n(input_dict, ['a', 'b', 'i']) == 1000
|
||||
assert exchange.safe_timestamp_n(input_dict, ['a', 'b', 'f']) == 123
|
||||
assert exchange.safe_timestamp_n(input_dict, ['a', 'b', 'strNumber']) == 3000
|
||||
assert exchange.safe_timestamp_n(input_list, [3, 2, 1]) == 2000
|
||||
# safeFloat
|
||||
# @ts-expect-error
|
||||
assert exchange.safe_float(input_dict, 'i') == float(1)
|
||||
assert exchange.safe_float(input_dict, 'f') == 0.123
|
||||
# @ts-expect-error
|
||||
assert exchange.safe_float(input_dict, 'strNumber') == float(3)
|
||||
# @ts-expect-error
|
||||
assert exchange.safe_float(input_list, 1) == float(2)
|
||||
# safeFloat2
|
||||
# @ts-expect-error
|
||||
assert exchange.safe_float_2(input_dict, 'a', 'i') == float(1)
|
||||
assert exchange.safe_float_2(input_dict, 'a', 'f') == 0.123
|
||||
# @ts-expect-error
|
||||
assert exchange.safe_float_2(input_dict, 'a', 'strNumber') == float(3)
|
||||
# @ts-expect-error
|
||||
assert exchange.safe_float_2(input_list, 2, 1) == float(2)
|
||||
# safeFloatN
|
||||
# @ts-expect-error
|
||||
assert exchange.safe_float_n(input_dict, ['a', 'b', 'i']) == float(1)
|
||||
assert exchange.safe_float_n(input_dict, ['a', 'b', 'f']) == 0.123
|
||||
# @ts-expect-error
|
||||
assert exchange.safe_float_n(input_dict, ['a', 'b', 'strNumber']) == float(3)
|
||||
# @ts-expect-error
|
||||
assert exchange.safe_float_n(input_list, [3, 2, 1]) == float(2)
|
||||
# safeNumber
|
||||
assert exchange.safe_number(input_dict, 'i') == exchange.parse_number(1)
|
||||
assert exchange.safe_number(input_dict, 'f') == exchange.parse_number(0.123)
|
||||
assert exchange.safe_number(input_dict, 'strNumber') == exchange.parse_number(3)
|
||||
assert exchange.safe_number(input_list, 1) == exchange.parse_number(2)
|
||||
assert exchange.safe_number(input_list, 'bool') is None
|
||||
assert exchange.safe_number(input_list, 'list') is None
|
||||
assert exchange.safe_number(input_list, 'dict') is None
|
||||
assert exchange.safe_number(input_list, 'str') is None
|
||||
# safeNumber2
|
||||
assert exchange.safe_number_2(input_dict, 'a', 'i') == exchange.parse_number(1)
|
||||
assert exchange.safe_number_2(input_dict, 'a', 'f') == exchange.parse_number(0.123)
|
||||
assert exchange.safe_number_2(input_dict, 'a', 'strNumber') == exchange.parse_number(3)
|
||||
assert exchange.safe_number_2(input_list, 2, 1) == exchange.parse_number(2)
|
||||
# safeNumberN
|
||||
assert exchange.safe_number_n(input_dict, ['a', 'b', 'i']) == exchange.parse_number(1)
|
||||
assert exchange.safe_number_n(input_dict, ['a', 'b', 'f']) == exchange.parse_number(0.123)
|
||||
assert exchange.safe_number_n(input_dict, ['a', 'b', 'strNumber']) == exchange.parse_number(3)
|
||||
assert exchange.safe_number_n(input_list, [3, 2, 1]) == exchange.parse_number(2)
|
||||
# safeBool
|
||||
assert exchange.safe_bool(input_dict, 'bool')
|
||||
assert exchange.safe_bool(input_list, 1) is None
|
||||
# safeBool2
|
||||
assert exchange.safe_bool_2(input_dict, 'a', 'bool')
|
||||
assert exchange.safe_bool_2(input_list, 2, 1) is None
|
||||
# safeBoolN
|
||||
assert exchange.safe_bool_n(input_dict, ['a', 'b', 'bool'])
|
||||
assert exchange.safe_bool_n(input_list, [3, 2, 1]) is None
|
||||
# safeNumberOmitZero
|
||||
assert exchange.safe_number_omit_zero(input_dict, 'zeroNumeric') is None
|
||||
assert exchange.safe_number_omit_zero(input_dict, 'zeroString') is None
|
||||
assert exchange.safe_number_omit_zero(input_dict, 'undefined') is None
|
||||
assert exchange.safe_number_omit_zero(input_dict, 'emptyString') is None
|
||||
assert exchange.safe_number_omit_zero(input_dict, 'floatNumeric') is not None
|
||||
assert exchange.safe_number_omit_zero(input_dict, 'floatString') is not None
|
||||
137
ccxt/test/base/test_safe_ticker.py
Normal file
137
ccxt/test/base/test_safe_ticker.py
Normal file
@@ -0,0 +1,137 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
from ccxt.base.precise import Precise # noqa E402
|
||||
|
||||
def precise_equal_str(exchange, result, key, expected):
|
||||
return Precise.string_eq(exchange.safe_string(result, key), expected)
|
||||
|
||||
|
||||
def test_safe_ticker():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
})
|
||||
# CASE 1 - by open
|
||||
ticker1 = {
|
||||
'open': 5,
|
||||
'change': 1,
|
||||
}
|
||||
result1 = exchange.safe_ticker(ticker1)
|
||||
assert precise_equal_str(exchange, result1, 'percentage', '20.0')
|
||||
assert precise_equal_str(exchange, result1, 'average', '5.5')
|
||||
assert precise_equal_str(exchange, result1, 'close', '6.0')
|
||||
assert precise_equal_str(exchange, result1, 'last', '6.0')
|
||||
# CASE 2 - by open
|
||||
ticker2 = {
|
||||
'open': 5,
|
||||
'percentage': 20,
|
||||
}
|
||||
result2 = exchange.safe_ticker(ticker2)
|
||||
assert precise_equal_str(exchange, result2, 'change', '1.0')
|
||||
assert precise_equal_str(exchange, result2, 'average', '5.5')
|
||||
assert precise_equal_str(exchange, result2, 'close', '6.0')
|
||||
assert precise_equal_str(exchange, result2, 'last', '6.0')
|
||||
# CASE 3 - by close
|
||||
ticker3 = {
|
||||
'close': 6,
|
||||
'change': 1,
|
||||
}
|
||||
result3 = exchange.safe_ticker(ticker3)
|
||||
assert precise_equal_str(exchange, result3, 'open', '5.0')
|
||||
assert precise_equal_str(exchange, result3, 'percentage', '20.0')
|
||||
assert precise_equal_str(exchange, result3, 'average', '5.5')
|
||||
assert precise_equal_str(exchange, result3, 'last', '6.0')
|
||||
# CASE 4 - by close
|
||||
ticker4 = {
|
||||
'close': 6,
|
||||
'percentage': 20,
|
||||
}
|
||||
result4 = exchange.safe_ticker(ticker4)
|
||||
assert precise_equal_str(exchange, result4, 'open', '5.0')
|
||||
assert precise_equal_str(exchange, result4, 'change', '1.0')
|
||||
assert precise_equal_str(exchange, result4, 'average', '5.5')
|
||||
assert precise_equal_str(exchange, result4, 'last', '6.0')
|
||||
# CASE 5 - by average
|
||||
ticker5 = {
|
||||
'average': 5.5,
|
||||
'percentage': 20,
|
||||
}
|
||||
result5 = exchange.safe_ticker(ticker5)
|
||||
assert precise_equal_str(exchange, result5, 'open', '5.0')
|
||||
assert precise_equal_str(exchange, result5, 'change', '1.0')
|
||||
assert precise_equal_str(exchange, result5, 'close', '6.0')
|
||||
assert precise_equal_str(exchange, result5, 'last', '6.0')
|
||||
# CASE 6
|
||||
ticker6 = {
|
||||
'average': 5.5,
|
||||
'change': 1,
|
||||
}
|
||||
result6 = exchange.safe_ticker(ticker6)
|
||||
assert precise_equal_str(exchange, result6, 'open', '5.0')
|
||||
assert precise_equal_str(exchange, result6, 'percentage', '20.0')
|
||||
assert precise_equal_str(exchange, result6, 'close', '6.0')
|
||||
assert precise_equal_str(exchange, result6, 'last', '6.0')
|
||||
# CASE 7 - by open and close
|
||||
ticker7 = {
|
||||
'open': 5,
|
||||
'close': 6,
|
||||
}
|
||||
result7 = exchange.safe_ticker(ticker7)
|
||||
assert precise_equal_str(exchange, result7, 'change', '1.0')
|
||||
assert precise_equal_str(exchange, result7, 'percentage', '20.0')
|
||||
assert precise_equal_str(exchange, result7, 'average', '5.5')
|
||||
assert precise_equal_str(exchange, result7, 'last', '6.0')
|
||||
# CASE 8 - full ticker
|
||||
ticker8 = {
|
||||
'open': 5,
|
||||
'close': 6,
|
||||
'last': 6,
|
||||
'high': 6.5,
|
||||
'low': 4.5,
|
||||
'average': 5.5,
|
||||
'bid': 5.9,
|
||||
'bidVolume': 100,
|
||||
'ask': 6.1,
|
||||
'askVolume': 200,
|
||||
'change': 1,
|
||||
'percentage': 20,
|
||||
'vwap': 5.75,
|
||||
'baseVolume': 1000,
|
||||
'quoteVolume': 5750,
|
||||
'previousClose': 4.9,
|
||||
'indexPrice': 5.8,
|
||||
'markPrice': 5.9,
|
||||
'info': {},
|
||||
}
|
||||
result8 = exchange.safe_ticker(ticker8)
|
||||
assert precise_equal_str(exchange, result8, 'open', '5.0')
|
||||
assert precise_equal_str(exchange, result8, 'high', '6.5')
|
||||
assert precise_equal_str(exchange, result8, 'low', '4.5')
|
||||
assert precise_equal_str(exchange, result8, 'close', '6.0')
|
||||
assert precise_equal_str(exchange, result8, 'last', '6.0')
|
||||
assert precise_equal_str(exchange, result8, 'change', '1.0')
|
||||
assert precise_equal_str(exchange, result8, 'percentage', '20.0')
|
||||
assert precise_equal_str(exchange, result8, 'average', '5.5')
|
||||
assert precise_equal_str(exchange, result8, 'bid', '5.9')
|
||||
assert precise_equal_str(exchange, result8, 'bidVolume', '100.0')
|
||||
assert precise_equal_str(exchange, result8, 'ask', '6.1')
|
||||
assert precise_equal_str(exchange, result8, 'askVolume', '200.0')
|
||||
assert precise_equal_str(exchange, result8, 'vwap', '5.75')
|
||||
assert precise_equal_str(exchange, result8, 'baseVolume', '1000.0')
|
||||
assert precise_equal_str(exchange, result8, 'quoteVolume', '5750.0')
|
||||
assert precise_equal_str(exchange, result8, 'previousClose', '4.9')
|
||||
assert precise_equal_str(exchange, result8, 'indexPrice', '5.8')
|
||||
assert precise_equal_str(exchange, result8, 'markPrice', '5.9')
|
||||
assert result8['info'] is not None
|
||||
25
ccxt/test/base/test_sort.py
Normal file
25
ccxt/test/base/test_sort.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
def test_sort():
|
||||
# todo: other argument checks
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
})
|
||||
arr = ['b', 'a', 'c', 'd']
|
||||
sorted_arr = exchange.sort(arr)
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'sort', sorted_arr, ['a', 'b', 'c', 'd'])
|
||||
65
ccxt/test/base/test_sort_by.py
Normal file
65
ccxt/test/base/test_sort_by.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
def test_sort_by():
|
||||
# todo: other argument checks
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
})
|
||||
arr = [{
|
||||
'x': 5,
|
||||
}, {
|
||||
'x': 2,
|
||||
}, {
|
||||
'x': 4,
|
||||
}, {
|
||||
'x': 0,
|
||||
}, {
|
||||
'x': 1,
|
||||
}, {
|
||||
'x': 3,
|
||||
}]
|
||||
new_array = exchange.sort_by(arr, 'x')
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'sortBy', new_array, [{
|
||||
'x': 0,
|
||||
}, {
|
||||
'x': 1,
|
||||
}, {
|
||||
'x': 2,
|
||||
}, {
|
||||
'x': 3,
|
||||
}, {
|
||||
'x': 4,
|
||||
}, {
|
||||
'x': 5,
|
||||
}])
|
||||
new_array_descending = exchange.sort_by(arr, 'x', True)
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'sortBy', new_array_descending, [{
|
||||
'x': 5,
|
||||
}, {
|
||||
'x': 4,
|
||||
}, {
|
||||
'x': 3,
|
||||
}, {
|
||||
'x': 2,
|
||||
}, {
|
||||
'x': 1,
|
||||
}, {
|
||||
'x': 0,
|
||||
}])
|
||||
empty_array = exchange.sort_by([], 'x')
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'sortBy', empty_array, [])
|
||||
24
ccxt/test/base/test_sum.py
Normal file
24
ccxt/test/base/test_sum.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ccxt # noqa: F402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
def test_sum():
|
||||
exchange = ccxt.Exchange({
|
||||
'id': 'sampleexchange',
|
||||
})
|
||||
# testSharedMethods.assertDeepEqual (exchange, undefined, 'testSum', exchange.sum (), undefined); # todo: bugs in py
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'testSum', exchange.sum(2), 2)
|
||||
test_shared_methods.assert_deep_equal(exchange, None, 'testSum', exchange.sum(2, 30, 400), 432)
|
||||
60
ccxt/test/base/tests_init.py
Normal file
60
ccxt/test/base/tests_init.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 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
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.base.decimal_to_precision import decimal_to_precision # noqa E402
|
||||
from ccxt.base.decimal_to_precision import number_to_string # noqa E402
|
||||
from ccxt.base.precise import Precise # noqa E402
|
||||
from ccxt.test.base.test_decimal_to_precision import test_decimal_to_precision # noqa E402
|
||||
from ccxt.test.base.test_number_to_string import test_number_to_string # noqa E402
|
||||
from ccxt.test.base.test_precise import test_precise # noqa E402
|
||||
from ccxt.test.base.test_datetime import test_datetime # noqa E402
|
||||
from ccxt.test.base.test_cryptography import test_cryptography # noqa E402
|
||||
from ccxt.test.base.test_extend import test_extend # noqa E402
|
||||
from ccxt.test.base.test_deep_extend import test_deep_extend # noqa E402
|
||||
from ccxt.test.base.language_specific.test_language_specific import test_language_specific # noqa E402
|
||||
from ccxt.test.base.test_safe_methods import test_safe_methods # noqa E402
|
||||
from ccxt.test.base.test_safe_ticker import test_safe_ticker # noqa E402
|
||||
from ccxt.test.base.test_sort_by import test_sort_by # noqa E402
|
||||
from ccxt.test.base.test_sum import test_sum # noqa E402
|
||||
from ccxt.test.base.test_omit import test_omit # noqa E402
|
||||
from ccxt.test.base.test_group_by import test_group_by # noqa E402
|
||||
from ccxt.test.base.test_filter_by import test_filter_by # noqa E402
|
||||
from ccxt.test.base.test_after_constructor import test_after_constructor # noqa E402
|
||||
from ccxt.test.base.test_handle_methods import test_handle_methods # noqa E402
|
||||
from ccxt.test.base.test_remove_repeated_elements_from_array import test_remove_repeated_elements_from_array # noqa E402
|
||||
from ccxt.test.base.test_parse_precision import test_parse_precision # noqa E402
|
||||
from ccxt.test.base.test_arrays_concat import test_arrays_concat # noqa E402
|
||||
|
||||
def base_tests_init():
|
||||
test_language_specific()
|
||||
test_after_constructor()
|
||||
test_extend()
|
||||
test_deep_extend()
|
||||
test_cryptography()
|
||||
test_datetime()
|
||||
test_decimal_to_precision()
|
||||
test_number_to_string()
|
||||
test_precise()
|
||||
test_safe_methods()
|
||||
test_safe_ticker()
|
||||
# testJson ();
|
||||
test_sort_by()
|
||||
test_sum()
|
||||
test_omit()
|
||||
test_group_by()
|
||||
test_filter_by()
|
||||
test_handle_methods()
|
||||
test_remove_repeated_elements_from_array()
|
||||
test_parse_precision()
|
||||
test_arrays_concat()
|
||||
Reference in New Issue
Block a user