Skip to content

Commit

Permalink
add affiliate endpoints. Pull Request #2
Browse files Browse the repository at this point in the history
  • Loading branch information
makarworld committed Oct 5, 2023
1 parent 3c888bb commit dfbf6d6
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 30 deletions.
6 changes: 4 additions & 2 deletions pymexc/base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from abc import ABC, abstractclassmethod
from typing import Union, Literal
import hmac, hashlib
import hmac
import hashlib
import requests
from urllib.parse import urlencode
import logging
import time

logger = logging.getLogger(__name__)

class MexcAPIError(Exception): pass
class MexcAPIError(Exception):
pass

class MexcSDK(ABC):
"""
Expand Down
3 changes: 2 additions & 1 deletion pymexc/base_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def _auth(self):
# make auth if futures. spot has a different auth system.

isspot = self.endpoint.startswith(SPOT)
if isspot: return
if isspot:
return

timestamp = str(int(time.time() * 1000))
_val = self.api_key + timestamp
Expand Down
18 changes: 9 additions & 9 deletions pymexc/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def handle_message(message):
try:
from base import _FuturesHTTP
from base_websocket import _FuturesWebSocket
except:
except ImportError:
from .base import _FuturesHTTP
from .base_websocket import _FuturesWebSocket

Expand Down Expand Up @@ -731,7 +731,7 @@ def order_deals(self,
:return: response dictionary
:rtype: dict
"""
return self.call("GET", f"api/v1/private/order/list/order_deals",
return self.call("GET", "api/v1/private/order/list/order_deals",
params = dict(
symbol = symbol,
start_time = start_time,
Expand Down Expand Up @@ -771,7 +771,7 @@ def get_trigger_orders(self,
:return: response dictionary
:rtype: dict
"""
return self.call("GET", f"api/v1/private/planorder/list/orders",
return self.call("GET", "api/v1/private/planorder/list/orders",
params = dict(
symbol = symbol,
states = states,
Expand Down Expand Up @@ -811,7 +811,7 @@ def get_stop_limit_orders(self,
:rtype: dict
"""

return self.call("GET", f"api/v1/private/stoporder/list/orders",
return self.call("GET", "api/v1/private/stoporder/list/orders",
params = dict(
symbol = symbol,
is_finished = is_finished,
Expand All @@ -836,7 +836,7 @@ def risk_limit(self, symbol: Optional[str] = None) -> dict:
:return: response dictionary
:rtype: dict
"""
return self.call("GET", f"api/v1/private/account/risk_limit",
return self.call("GET", "api/v1/private/account/risk_limit",
params = dict(
symbol = symbol
))
Expand All @@ -857,7 +857,7 @@ def tiered_fee_rate(self, symbol: Optional[str] = None) -> dict:
:rtype: dict
"""

return self.call("GET", f"api/v1/private/account/tiered_fee_rate",
return self.call("GET", "api/v1/private/account/tiered_fee_rate",
params = dict(
symbol = symbol
))
Expand All @@ -884,7 +884,7 @@ def change_margin(self,
:return: response dictionary
:rtype: dict
"""
return self.call("POST", f"api/v1/private/position/change_margin",
return self.call("POST", "api/v1/private/position/change_margin",
params = dict(
positionId = position_id,
amount = amount,
Expand All @@ -907,7 +907,7 @@ def get_leverage(self, symbol: str) -> dict:
:rtype: dict
"""

return self.call("GET", f"api/v1/private/position/leverage",
return self.call("GET", "api/v1/private/position/leverage",
params = dict(
symbol = symbol
))
Expand Down Expand Up @@ -941,7 +941,7 @@ def change_leverage(self,
:rtype: dict
"""

return self.call("POST", f"api/v1/private/position/change_leverage",
return self.call("POST", "api/v1/private/position/change_leverage",
params = dict(
positionId = position_id,
leverage = leverage,
Expand Down
137 changes: 120 additions & 17 deletions pymexc/spot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ def handle_message(message):
"""
from typing import Callable, Literal, List, Optional, Union
import threading, time, logging
import threading
import time
import logging

logger = logging.getLogger(__name__)

try:
from base import _SpotHTTP
from base_websocket import _SpotWebSocket
except:
except ImportError:
from .base import _SpotHTTP
from .base_websocket import _SpotWebSocket

Expand Down Expand Up @@ -551,20 +553,6 @@ def query_universal_transfer_history(self,
#
# <=================================================================>

def all_orders(self,
symbol: str,
start_time: Optional[int] = None,
end_time: Optional[int] = None,
limit: Optional[int] = 500) -> dict:

return self.call("GET", "/api/v3/allOrders",
params = dict(
symbol = symbol,
startTime = start_time,
endTime = end_time,
limit = limit
))

def get_default_symbols(self) -> dict:
"""
### User API default symbol.
Expand Down Expand Up @@ -1315,7 +1303,7 @@ def user_universal_transfer_history_by_tranid(self, tran_id: str) -> dict:
:return: response dictionary
:rtype: dict
"""
return self.call("GET", f"api/v3/capital/transfer/tranId", params=dict(tranId=tran_id))
return self.call("GET", "api/v3/capital/transfer/tranId", params=dict(tranId=tran_id))

def get_assets_convert_into_mx(self) -> dict:
"""
Expand Down Expand Up @@ -1577,6 +1565,121 @@ def query_refercode(self) -> dict:
"""
return self.call("GET", "api/v3/rebate/referCode", params=dict(please_sign_me = None))

def affiliate_commission_record(self,
start_time: Optional[int] = None,
end_time: Optional[int] = None,
invite_code: Optional[int] = None,
page: Optional[int] = None,
page_size: Optional[int] = None) -> dict:
"""
### Get Affiliate Commission Record (affiliate only)
#### Required permission: SPOT_ACCOUNT_READ
Weight(IP): 1
https://mexcdevelop.github.io/apidocs/spot_v3_en/#get-affiliate-commission-record-affiliate-only
:param start_time: (optional)
:type start_time: int
:param end_time: (optional)
:type end_time: int
:param invite_code: (optional)
:type invite_code: int
:param page: (optional) default 1
:type page: int
:param page_size: (optional) default 10
:type page_size: int
:return: response dictionary
:rtype: dict
"""
return self.call("GET", "/api/v3/rebate/affiliate/commission",
params = dict(
startTime = start_time,
endTime = end_time,
inviteCode = invite_code,
page = page,
pageSize = page_size
))

def affiliate_withdraw_record(self,
start_time: Optional[int] = None,
end_time: Optional[int] = None,
invite_code: Optional[int] = None,
page: Optional[int] = None,
page_size: Optional[int] = None) -> dict:
"""
### Get Affiliate Withdraw Record (affiliate only)
#### Required permission: SPOT_ACCOUNT_READ
Weight(IP): 1
https://mexcdevelop.github.io/apidocs/spot_v3_en/#get-affiliate-withdraw-record-affiliate-only
:param start_time: (optional)
:type start_time: int
:param end_time: (optional)
:type end_time: int
:param invite_code: (optional)
:type invite_code: int
:param page: (optional) default 1
:type page: int
:param page_size: (optional) default 10
:type page_size: int
:return: response dictionary
:rtype: dict
"""
return self.call("GET", "/api/v3/rebate/affiliate/withdraw",
params = dict(
startTime = start_time,
endTime = end_time,
inviteCode = invite_code,
page = page,
pageSize = page_size
))

def affiliate_commission_detail_record(self,
start_time: Optional[int] = None,
end_time: Optional[int] = None,
invite_code: Optional[int] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
type: Optional[Literal[1, 2, 3]] = None) -> dict:
"""
### Get Affiliate Withdraw Record (affiliate only)
#### Required permission: SPOT_ACCOUNT_READ
Weight(IP): 1
https://mexcdevelop.github.io/apidocs/spot_v3_en/#get-affiliate-withdraw-record-affiliate-only
:param start_time: (optional)
:type start_time: int
:param end_time: (optional)
:type end_time: int
:param invite_code: (optional)
:type invite_code: int
:param page: (optional) default 1
:type page: int
:param page_size: (optional) default 10
:type page_size: int
:param type: (optional) commission type, 1:spot, 2:futures, 3:ETF
:type type: int
:return: response dictionary
:rtype: dict
"""
return self.call("GET", "/api/v3/rebate/affiliate/commission/detail",
params = dict(
startTime = start_time,
endTime = end_time,
inviteCode = invite_code,
page = page,
pageSize = page_size,
type = type
))

class WebSocket(_SpotWebSocket):
def __init__(self,
api_key: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""


version = '1.0.9'
version = '1.0.10'

with open("README.md", "r") as f:
long_description = f.read()
Expand Down

0 comments on commit dfbf6d6

Please sign in to comment.