Merge branch 'develop' into feat_readjust_entry

This commit is contained in:
eSeR1805 2022-04-18 21:22:19 +03:00
commit cea4f663d5
No known key found for this signature in database
GPG Key ID: BA53686259B46936
9 changed files with 4412 additions and 4412 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2137,8 +2137,8 @@ class Exchange:
def parse_leverage_tier(self, tier) -> Dict: def parse_leverage_tier(self, tier) -> Dict:
info = tier.get('info', {}) info = tier.get('info', {})
return { return {
'min': tier['notionalFloor'], 'min': tier['minNotional'],
'max': tier['notionalCap'], 'max': tier['maxNotional'],
'mmr': tier['maintenanceMarginRate'], 'mmr': tier['maintenanceMarginRate'],
'lev': tier['maxLeverage'], 'lev': tier['maxLeverage'],
'maintAmt': float(info['cum']) if 'cum' in info else None, 'maintAmt': float(info['cum']) if 'cum' in info else None,

View File

@ -19,13 +19,13 @@ isort==5.10.1
time-machine==2.6.0 time-machine==2.6.0
# Convert jupyter notebooks to markdown documents # Convert jupyter notebooks to markdown documents
nbconvert==6.4.5 nbconvert==6.5.0
# mypy types # mypy types
types-cachetools==5.0.0 types-cachetools==5.0.1
types-filelock==3.2.5 types-filelock==3.2.5
types-requests==2.27.16 types-requests==2.27.19
types-tabulate==0.8.6 types-tabulate==0.8.7
# Extensions to datetime library # Extensions to datetime library
types-python-dateutil==2.8.10 types-python-dateutil==2.8.11

View File

@ -2,7 +2,7 @@ numpy==1.22.3
pandas==1.4.2 pandas==1.4.2
pandas-ta==0.3.14b pandas-ta==0.3.14b
ccxt==1.78.62 ccxt==1.79.81
# Pin cryptography for now due to rust build errors with piwheels # Pin cryptography for now due to rust build errors with piwheels
cryptography==36.0.2 cryptography==36.0.2
aiohttp==3.8.1 aiohttp==3.8.1
@ -31,7 +31,7 @@ python-rapidjson==1.6
sdnotify==0.3.2 sdnotify==0.3.2
# API Server # API Server
fastapi==0.75.1 fastapi==0.75.2
uvicorn==0.17.6 uvicorn==0.17.6
pyjwt==2.3.0 pyjwt==2.3.0
aiofiles==0.8.0 aiofiles==0.8.0

View File

@ -42,7 +42,7 @@ setup(
], ],
install_requires=[ install_requires=[
# from requirements.txt # from requirements.txt
'ccxt>=1.77.29', 'ccxt>=1.79.69',
'SQLAlchemy', 'SQLAlchemy',
'python-telegram-bot>=13.4', 'python-telegram-bot>=13.4',
'arrow>=0.17.0', 'arrow>=0.17.0',

View File

@ -169,90 +169,90 @@ def test_fill_leverage_tiers_binance(default_conf, mocker):
'ADA/BUSD': [ 'ADA/BUSD': [
{ {
"tier": 1, "tier": 1,
"notionalFloor": 0, "minNotional": 0,
"notionalCap": 100000, "maxNotional": 100000,
"maintenanceMarginRate": 0.025, "maintenanceMarginRate": 0.025,
"maxLeverage": 20, "maxLeverage": 20,
"info": { "info": {
"bracket": "1", "bracket": "1",
"initialLeverage": "20", "initialLeverage": "20",
"notionalCap": "100000", "maxNotional": "100000",
"notionalFloor": "0", "minNotional": "0",
"maintMarginRatio": "0.025", "maintMarginRatio": "0.025",
"cum": "0.0" "cum": "0.0"
} }
}, },
{ {
"tier": 2, "tier": 2,
"notionalFloor": 100000, "minNotional": 100000,
"notionalCap": 500000, "maxNotional": 500000,
"maintenanceMarginRate": 0.05, "maintenanceMarginRate": 0.05,
"maxLeverage": 10, "maxLeverage": 10,
"info": { "info": {
"bracket": "2", "bracket": "2",
"initialLeverage": "10", "initialLeverage": "10",
"notionalCap": "500000", "maxNotional": "500000",
"notionalFloor": "100000", "minNotional": "100000",
"maintMarginRatio": "0.05", "maintMarginRatio": "0.05",
"cum": "2500.0" "cum": "2500.0"
} }
}, },
{ {
"tier": 3, "tier": 3,
"notionalFloor": 500000, "minNotional": 500000,
"notionalCap": 1000000, "maxNotional": 1000000,
"maintenanceMarginRate": 0.1, "maintenanceMarginRate": 0.1,
"maxLeverage": 5, "maxLeverage": 5,
"info": { "info": {
"bracket": "3", "bracket": "3",
"initialLeverage": "5", "initialLeverage": "5",
"notionalCap": "1000000", "maxNotional": "1000000",
"notionalFloor": "500000", "minNotional": "500000",
"maintMarginRatio": "0.1", "maintMarginRatio": "0.1",
"cum": "27500.0" "cum": "27500.0"
} }
}, },
{ {
"tier": 4, "tier": 4,
"notionalFloor": 1000000, "minNotional": 1000000,
"notionalCap": 2000000, "maxNotional": 2000000,
"maintenanceMarginRate": 0.15, "maintenanceMarginRate": 0.15,
"maxLeverage": 3, "maxLeverage": 3,
"info": { "info": {
"bracket": "4", "bracket": "4",
"initialLeverage": "3", "initialLeverage": "3",
"notionalCap": "2000000", "maxNotional": "2000000",
"notionalFloor": "1000000", "minNotional": "1000000",
"maintMarginRatio": "0.15", "maintMarginRatio": "0.15",
"cum": "77500.0" "cum": "77500.0"
} }
}, },
{ {
"tier": 5, "tier": 5,
"notionalFloor": 2000000, "minNotional": 2000000,
"notionalCap": 5000000, "maxNotional": 5000000,
"maintenanceMarginRate": 0.25, "maintenanceMarginRate": 0.25,
"maxLeverage": 2, "maxLeverage": 2,
"info": { "info": {
"bracket": "5", "bracket": "5",
"initialLeverage": "2", "initialLeverage": "2",
"notionalCap": "5000000", "maxNotional": "5000000",
"notionalFloor": "2000000", "minNotional": "2000000",
"maintMarginRatio": "0.25", "maintMarginRatio": "0.25",
"cum": "277500.0" "cum": "277500.0"
} }
}, },
{ {
"tier": 6, "tier": 6,
"notionalFloor": 5000000, "minNotional": 5000000,
"notionalCap": 30000000, "maxNotional": 30000000,
"maintenanceMarginRate": 0.5, "maintenanceMarginRate": 0.5,
"maxLeverage": 1, "maxLeverage": 1,
"info": { "info": {
"bracket": "6", "bracket": "6",
"initialLeverage": "1", "initialLeverage": "1",
"notionalCap": "30000000", "maxNotional": "30000000",
"notionalFloor": "5000000", "minNotional": "5000000",
"maintMarginRatio": "0.5", "maintMarginRatio": "0.5",
"cum": "1527500.0" "cum": "1527500.0"
} }
@ -261,105 +261,105 @@ def test_fill_leverage_tiers_binance(default_conf, mocker):
"ZEC/USDT": [ "ZEC/USDT": [
{ {
"tier": 1, "tier": 1,
"notionalFloor": 0, "minNotional": 0,
"notionalCap": 50000, "maxNotional": 50000,
"maintenanceMarginRate": 0.01, "maintenanceMarginRate": 0.01,
"maxLeverage": 50, "maxLeverage": 50,
"info": { "info": {
"bracket": "1", "bracket": "1",
"initialLeverage": "50", "initialLeverage": "50",
"notionalCap": "50000", "maxNotional": "50000",
"notionalFloor": "0", "minNotional": "0",
"maintMarginRatio": "0.01", "maintMarginRatio": "0.01",
"cum": "0.0" "cum": "0.0"
} }
}, },
{ {
"tier": 2, "tier": 2,
"notionalFloor": 50000, "minNotional": 50000,
"notionalCap": 150000, "maxNotional": 150000,
"maintenanceMarginRate": 0.025, "maintenanceMarginRate": 0.025,
"maxLeverage": 20, "maxLeverage": 20,
"info": { "info": {
"bracket": "2", "bracket": "2",
"initialLeverage": "20", "initialLeverage": "20",
"notionalCap": "150000", "maxNotional": "150000",
"notionalFloor": "50000", "minNotional": "50000",
"maintMarginRatio": "0.025", "maintMarginRatio": "0.025",
"cum": "750.0" "cum": "750.0"
} }
}, },
{ {
"tier": 3, "tier": 3,
"notionalFloor": 150000, "minNotional": 150000,
"notionalCap": 250000, "maxNotional": 250000,
"maintenanceMarginRate": 0.05, "maintenanceMarginRate": 0.05,
"maxLeverage": 10, "maxLeverage": 10,
"info": { "info": {
"bracket": "3", "bracket": "3",
"initialLeverage": "10", "initialLeverage": "10",
"notionalCap": "250000", "maxNotional": "250000",
"notionalFloor": "150000", "minNotional": "150000",
"maintMarginRatio": "0.05", "maintMarginRatio": "0.05",
"cum": "4500.0" "cum": "4500.0"
} }
}, },
{ {
"tier": 4, "tier": 4,
"notionalFloor": 250000, "minNotional": 250000,
"notionalCap": 500000, "maxNotional": 500000,
"maintenanceMarginRate": 0.1, "maintenanceMarginRate": 0.1,
"maxLeverage": 5, "maxLeverage": 5,
"info": { "info": {
"bracket": "4", "bracket": "4",
"initialLeverage": "5", "initialLeverage": "5",
"notionalCap": "500000", "maxNotional": "500000",
"notionalFloor": "250000", "minNotional": "250000",
"maintMarginRatio": "0.1", "maintMarginRatio": "0.1",
"cum": "17000.0" "cum": "17000.0"
} }
}, },
{ {
"tier": 5, "tier": 5,
"notionalFloor": 500000, "minNotional": 500000,
"notionalCap": 1000000, "maxNotional": 1000000,
"maintenanceMarginRate": 0.125, "maintenanceMarginRate": 0.125,
"maxLeverage": 4, "maxLeverage": 4,
"info": { "info": {
"bracket": "5", "bracket": "5",
"initialLeverage": "4", "initialLeverage": "4",
"notionalCap": "1000000", "maxNotional": "1000000",
"notionalFloor": "500000", "minNotional": "500000",
"maintMarginRatio": "0.125", "maintMarginRatio": "0.125",
"cum": "29500.0" "cum": "29500.0"
} }
}, },
{ {
"tier": 6, "tier": 6,
"notionalFloor": 1000000, "minNotional": 1000000,
"notionalCap": 2000000, "maxNotional": 2000000,
"maintenanceMarginRate": 0.25, "maintenanceMarginRate": 0.25,
"maxLeverage": 2, "maxLeverage": 2,
"info": { "info": {
"bracket": "6", "bracket": "6",
"initialLeverage": "2", "initialLeverage": "2",
"notionalCap": "2000000", "maxNotional": "2000000",
"notionalFloor": "1000000", "minNotional": "1000000",
"maintMarginRatio": "0.25", "maintMarginRatio": "0.25",
"cum": "154500.0" "cum": "154500.0"
} }
}, },
{ {
"tier": 7, "tier": 7,
"notionalFloor": 2000000, "minNotional": 2000000,
"notionalCap": 30000000, "maxNotional": 30000000,
"maintenanceMarginRate": 0.5, "maintenanceMarginRate": 0.5,
"maxLeverage": 1, "maxLeverage": 1,
"info": { "info": {
"bracket": "7", "bracket": "7",
"initialLeverage": "1", "initialLeverage": "1",
"notionalCap": "30000000", "maxNotional": "30000000",
"notionalFloor": "2000000", "minNotional": "2000000",
"maintMarginRatio": "0.5", "maintMarginRatio": "0.5",
"cum": "654500.0" "cum": "654500.0"
} }

View File

@ -369,25 +369,25 @@ class TestCCXTExchange():
pair_tiers = leverage_tiers[futures_pair] pair_tiers = leverage_tiers[futures_pair]
assert len(pair_tiers) > 0 assert len(pair_tiers) > 0
oldLeverage = float('inf') oldLeverage = float('inf')
oldMaintenanceMarginRate = oldNotionalFloor = oldNotionalCap = -1 oldMaintenanceMarginRate = oldminNotional = oldmaxNotional = -1
for tier in pair_tiers: for tier in pair_tiers:
for key in [ for key in [
'maintenanceMarginRate', 'maintenanceMarginRate',
'notionalFloor', 'minNotional',
'notionalCap', 'maxNotional',
'maxLeverage' 'maxLeverage'
]: ]:
assert key in tier assert key in tier
assert tier[key] >= 0.0 assert tier[key] >= 0.0
assert tier['notionalCap'] > tier['notionalFloor'] assert tier['maxNotional'] > tier['minNotional']
assert tier['maxLeverage'] <= oldLeverage assert tier['maxLeverage'] <= oldLeverage
assert tier['maintenanceMarginRate'] >= oldMaintenanceMarginRate assert tier['maintenanceMarginRate'] >= oldMaintenanceMarginRate
assert tier['notionalFloor'] > oldNotionalFloor assert tier['minNotional'] > oldminNotional
assert tier['notionalCap'] > oldNotionalCap assert tier['maxNotional'] > oldmaxNotional
oldLeverage = tier['maxLeverage'] oldLeverage = tier['maxLeverage']
oldMaintenanceMarginRate = tier['maintenanceMarginRate'] oldMaintenanceMarginRate = tier['maintenanceMarginRate']
oldNotionalFloor = tier['notionalFloor'] oldminNotional = tier['minNotional']
oldNotionalCap = tier['notionalCap'] oldmaxNotional = tier['maxNotional']
def test_ccxt_dry_run_liquidation_price(self, exchange_futures): def test_ccxt_dry_run_liquidation_price(self, exchange_futures):
futures, futures_name = exchange_futures futures, futures_name = exchange_futures

View File

@ -4507,8 +4507,8 @@ def test_load_leverage_tiers(mocker, default_conf, leverage_tiers, exchange_name
'ADA/USDT:USDT': [ 'ADA/USDT:USDT': [
{ {
'tier': 1, 'tier': 1,
'notionalFloor': 0, 'minNotional': 0,
'notionalCap': 500, 'maxNotional': 500,
'maintenanceMarginRate': 0.02, 'maintenanceMarginRate': 0.02,
'maxLeverage': 75, 'maxLeverage': 75,
'info': { 'info': {
@ -4548,8 +4548,8 @@ def test_load_leverage_tiers(mocker, default_conf, leverage_tiers, exchange_name
'ADA/USDT:USDT': [ 'ADA/USDT:USDT': [
{ {
'tier': 1, 'tier': 1,
'notionalFloor': 0, 'minNotional': 0,
'notionalCap': 500, 'maxNotional': 500,
'maintenanceMarginRate': 0.02, 'maintenanceMarginRate': 0.02,
'maxLeverage': 75, 'maxLeverage': 75,
'info': { 'info': {
@ -4584,15 +4584,15 @@ def test_parse_leverage_tier(mocker, default_conf):
tier = { tier = {
"tier": 1, "tier": 1,
"notionalFloor": 0, "minNotional": 0,
"notionalCap": 100000, "maxNotional": 100000,
"maintenanceMarginRate": 0.025, "maintenanceMarginRate": 0.025,
"maxLeverage": 20, "maxLeverage": 20,
"info": { "info": {
"bracket": "1", "bracket": "1",
"initialLeverage": "20", "initialLeverage": "20",
"notionalCap": "100000", "maxNotional": "100000",
"notionalFloor": "0", "minNotional": "0",
"maintMarginRatio": "0.025", "maintMarginRatio": "0.025",
"cum": "0.0" "cum": "0.0"
} }
@ -4608,8 +4608,8 @@ def test_parse_leverage_tier(mocker, default_conf):
tier2 = { tier2 = {
'tier': 1, 'tier': 1,
'notionalFloor': 0, 'minNotional': 0,
'notionalCap': 2000, 'maxNotional': 2000,
'maintenanceMarginRate': 0.01, 'maintenanceMarginRate': 0.01,
'maxLeverage': 75, 'maxLeverage': 75,
'info': { 'info': {

View File

@ -19,8 +19,8 @@ def test_get_maintenance_ratio_and_amt_okx(
'ETH/USDT:USDT': [ 'ETH/USDT:USDT': [
{ {
'tier': 1, 'tier': 1,
'notionalFloor': 0, 'minNotional': 0,
'notionalCap': 2000, 'maxNotional': 2000,
'maintenanceMarginRate': 0.01, 'maintenanceMarginRate': 0.01,
'maxLeverage': 75, 'maxLeverage': 75,
'info': { 'info': {
@ -39,8 +39,8 @@ def test_get_maintenance_ratio_and_amt_okx(
}, },
{ {
'tier': 2, 'tier': 2,
'notionalFloor': 2001, 'minNotional': 2001,
'notionalCap': 4000, 'maxNotional': 4000,
'maintenanceMarginRate': 0.015, 'maintenanceMarginRate': 0.015,
'maxLeverage': 50, 'maxLeverage': 50,
'info': { 'info': {
@ -59,8 +59,8 @@ def test_get_maintenance_ratio_and_amt_okx(
}, },
{ {
'tier': 3, 'tier': 3,
'notionalFloor': 4001, 'minNotional': 4001,
'notionalCap': 8000, 'maxNotional': 8000,
'maintenanceMarginRate': 0.02, 'maintenanceMarginRate': 0.02,
'maxLeverage': 20, 'maxLeverage': 20,
'info': { 'info': {
@ -81,8 +81,8 @@ def test_get_maintenance_ratio_and_amt_okx(
'ADA/USDT:USDT': [ 'ADA/USDT:USDT': [
{ {
'tier': 1, 'tier': 1,
'notionalFloor': 0, 'minNotional': 0,
'notionalCap': 500, 'maxNotional': 500,
'maintenanceMarginRate': 0.02, 'maintenanceMarginRate': 0.02,
'maxLeverage': 75, 'maxLeverage': 75,
'info': { 'info': {
@ -101,8 +101,8 @@ def test_get_maintenance_ratio_and_amt_okx(
}, },
{ {
'tier': 2, 'tier': 2,
'notionalFloor': 501, 'minNotional': 501,
'notionalCap': 1000, 'maxNotional': 1000,
'maintenanceMarginRate': 0.025, 'maintenanceMarginRate': 0.025,
'maxLeverage': 50, 'maxLeverage': 50,
'info': { 'info': {
@ -121,8 +121,8 @@ def test_get_maintenance_ratio_and_amt_okx(
}, },
{ {
'tier': 3, 'tier': 3,
'notionalFloor': 1001, 'minNotional': 1001,
'notionalCap': 2000, 'maxNotional': 2000,
'maintenanceMarginRate': 0.03, 'maintenanceMarginRate': 0.03,
'maxLeverage': 20, 'maxLeverage': 20,
'info': { 'info': {
@ -180,8 +180,8 @@ def test_load_leverage_tiers_okx(default_conf, mocker, markets):
[ [
{ {
'tier': 1, 'tier': 1,
'notionalFloor': 0, 'minNotional': 0,
'notionalCap': 500, 'maxNotional': 500,
'maintenanceMarginRate': 0.02, 'maintenanceMarginRate': 0.02,
'maxLeverage': 75, 'maxLeverage': 75,
'info': { 'info': {
@ -200,8 +200,8 @@ def test_load_leverage_tiers_okx(default_conf, mocker, markets):
}, },
{ {
'tier': 2, 'tier': 2,
'notionalFloor': 501, 'minNotional': 501,
'notionalCap': 1000, 'maxNotional': 1000,
'maintenanceMarginRate': 0.025, 'maintenanceMarginRate': 0.025,
'maxLeverage': 50, 'maxLeverage': 50,
'info': { 'info': {
@ -220,8 +220,8 @@ def test_load_leverage_tiers_okx(default_conf, mocker, markets):
}, },
{ {
'tier': 3, 'tier': 3,
'notionalFloor': 1001, 'minNotional': 1001,
'notionalCap': 2000, 'maxNotional': 2000,
'maintenanceMarginRate': 0.03, 'maintenanceMarginRate': 0.03,
'maxLeverage': 20, 'maxLeverage': 20,
'info': { 'info': {
@ -242,8 +242,8 @@ def test_load_leverage_tiers_okx(default_conf, mocker, markets):
[ [
{ {
'tier': 1, 'tier': 1,
'notionalFloor': 0, 'minNotional': 0,
'notionalCap': 2000, 'maxNotional': 2000,
'maintenanceMarginRate': 0.01, 'maintenanceMarginRate': 0.01,
'maxLeverage': 75, 'maxLeverage': 75,
'info': { 'info': {
@ -262,8 +262,8 @@ def test_load_leverage_tiers_okx(default_conf, mocker, markets):
}, },
{ {
'tier': 2, 'tier': 2,
'notionalFloor': 2001, 'minNotional': 2001,
'notionalCap': 4000, 'maxNotional': 4000,
'maintenanceMarginRate': 0.015, 'maintenanceMarginRate': 0.015,
'maxLeverage': 50, 'maxLeverage': 50,
'info': { 'info': {
@ -282,8 +282,8 @@ def test_load_leverage_tiers_okx(default_conf, mocker, markets):
}, },
{ {
'tier': 3, 'tier': 3,
'notionalFloor': 4001, 'minNotional': 4001,
'notionalCap': 8000, 'maxNotional': 8000,
'maintenanceMarginRate': 0.02, 'maintenanceMarginRate': 0.02,
'maxLeverage': 20, 'maxLeverage': 20,
'info': { 'info': {