Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dydx/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _make_solo_order(
baseMarket, quoteMarket = utils.pair_to_base_quote_markets(market)
isBuy = utils.get_is_buy(side)
if limitFee is None:
limitFee = utils.get_limit_fee(baseMarket, amount, postOnly)
limitFee = utils.get_limit_fee(baseMarket, amount)

order = {
'salt': random.randint(0, 2**256),
Expand Down Expand Up @@ -167,7 +167,7 @@ def _make_perp_order(
baseMarket, _ = utils.pair_to_base_quote_markets(market)
isBuy = utils.get_is_buy(side)
if limitFee is None:
limitFee = utils.get_limit_fee(baseMarket, amount, postOnly)
limitFee = utils.get_limit_fee(baseMarket, amount)

order = {
'salt': random.randint(0, 2**256),
Expand Down
14 changes: 3 additions & 11 deletions dydx/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
MARKET_USDC = 2
MARKET_DAI = 3
MARKET_PBTC = 'PBTC'
MARKET_PUSD = 'PUSD'
MARKET_INVALID = 4

# ------------ Pairs ------------
PAIR_WETH_DAI = 'WETH-DAI'
PAIR_WETH_USDC = 'WETH-USDC'
PAIR_DAI_USDC = 'DAI-USDC'
PAIR_PBTC_USDC = 'PBTC-USDC'
PAIR_WETH_PUSD = 'WETH_PUSD'

DECIMALS_WETH = 18
DECIMALS_SAI = 18
Expand All @@ -53,17 +55,7 @@

# ------------ Fees ------------
FROM_BIPS = Decimal('1e-4')
SMALL_TRADE_SIZE_WETH = 20 * (10 ** DECIMALS_WETH)
SMALL_TRADE_SIZE_DAI = 10000 * (10 ** DECIMALS_DAI)
SMALL_TRADE_SIZE_PBTC = 0.5 * (10 ** DECIMALS_PBTC)
FEE_SMALL_WETH = Decimal(100) * FROM_BIPS
FEE_LARGE_WETH = Decimal(15) * FROM_BIPS
FEE_SMALL_DAI = Decimal(100) * FROM_BIPS
FEE_LARGE_DAI = Decimal(5) * FROM_BIPS
FEE_LARGE_PBTC = Decimal(7.5) * FROM_BIPS
FEE_SMALL_PBTC = Decimal(50) * FROM_BIPS
FEE_MAKER_PBTC = Decimal(-2.5) * FROM_BIPS
FEE_ZERO = Decimal(0)
LIMIT_FEE = Decimal(100) * FROM_BIPS

# ------------ Transaction Constants ------------
DEFAULT_GAS_AMOUNT = 250000
Expand Down
29 changes: 4 additions & 25 deletions dydx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def pair_to_base_quote_markets(pair):
return (consts.MARKET_DAI, consts.MARKET_USDC)
elif pair == consts.PAIR_PBTC_USDC:
return (consts.MARKET_PBTC, consts.MARKET_USDC)
elif pair == consts.PAIR_WETH_PUSD:
return (consts.MARKET_PUSD, consts.MARKET_WETH)
raise ValueError('Invalid pair')


Expand All @@ -106,31 +108,8 @@ def get_is_buy(side):
raise ValueError('Invalid side')


def get_limit_fee(base_market, amount, postOnly):
if postOnly:
if base_market == consts.MARKET_PBTC:
if (amount < consts.SMALL_TRADE_SIZE_PBTC):
return consts.FEE_ZERO
else:
return consts.FEE_MAKER_PBTC
else:
return consts.FEE_ZERO
if base_market == consts.MARKET_WETH:
if (amount < consts.SMALL_TRADE_SIZE_WETH):
return consts.FEE_SMALL_WETH
else:
return consts.FEE_LARGE_WETH
elif base_market == consts.MARKET_DAI:
if (amount < consts.SMALL_TRADE_SIZE_DAI):
return consts.FEE_SMALL_DAI
else:
return consts.FEE_LARGE_DAI
elif base_market == consts.MARKET_PBTC:
if (amount < consts.SMALL_TRADE_SIZE_PBTC):
return consts.FEE_SMALL_PBTC
else:
return consts.FEE_LARGE_PBTC
raise ValueError('Invalid base_market')
def get_limit_fee(base_market, amount):
return consts.LIMIT_FEE


def decimalToStr(d):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _additional_matcher(request):
assert order['amount'] == str(args['amount'])
assert order['limitPrice'] == str(args['limitPrice'])
assert order['triggerPrice'] == '0'
assert order['limitFee'] == '0.00075'
assert order['limitFee'] == '0.01'
assert order['maker'] == client.public_address
assert order['taker'] == consts.TAKER_ACCOUNT_OWNER
assert abs(
Expand Down