Skip to content

Commit

Permalink
[Mod] rename BinacneUsdtGateway as BinanceLinearGateway
Browse files Browse the repository at this point in the history
  • Loading branch information
veighna-global committed Mar 12, 2024
1 parent 415ef91 commit 1856cbf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ from vnpy.trader.ui import MainWindow, create_qapp
import vnpy_evo
from vnpy_binance import (
BinanceSpotGateway,
BinanceUsdtGateway,
BinanceLinearGateway,
BinanceInverseGateway
)
Expand All @@ -63,7 +63,7 @@ def main():
event_engine = EventEngine()
main_engine = MainEngine(event_engine)
main_engine.add_gateway(BinanceSpotGateway)
main_engine.add_gateway(BinanceUsdtGateway)
main_engine.add_gateway(BinanceLinearGateway)
main_engine.add_gateway(BinanceInverseGateway)
main_window = MainWindow(main_engine, event_engine)
Expand Down
4 changes: 2 additions & 2 deletions script/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from vnpy_binance import (
BinanceSpotGateway,
BinanceUsdtGateway,
BinanceLinearGateway,
BinanceInverseGateway
)

Expand All @@ -16,7 +16,7 @@ def main():
event_engine = EventEngine()
main_engine = MainEngine(event_engine)
main_engine.add_gateway(BinanceSpotGateway)
main_engine.add_gateway(BinanceUsdtGateway)
main_engine.add_gateway(BinanceLinearGateway)
main_engine.add_gateway(BinanceInverseGateway)

main_window = MainWindow(main_engine, event_engine)
Expand Down
4 changes: 2 additions & 2 deletions vnpy_binance/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The MIT License (MIT)
#
# Copyright (c) 2015-present, vn-crypto
# Copyright (c) 2015-present, VeighNa Global
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,7 +23,7 @@
import importlib_metadata

from .binance_spot_gateway import BinanceSpotGateway
from .binance_usdt_gateway import BinanceUsdtGateway
from .binance_linear_gateway import BinanceLinearGateway, BinanceUsdtGateway
from .binance_inverse_gateway import BinanceInverseGateway


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ class Security(Enum):
API_KEY: int = 2


class BinanceUsdtGateway(BaseGateway):
class BinanceLinearGateway(BaseGateway):
"""
The Binance USDT trading gateway for VeighNa.
The Binance linear trading gateway for VeighNa.
1. Only support crossed position
2. Only support one-way mode
"""

default_name: str = "BINANCE_USDT"
default_name: str = "BINANCE_LINEAR"

default_setting: dict = {
"API Key": "",
Expand All @@ -138,9 +138,9 @@ def __init__(self, event_engine: EventEngine, gateway_name: str) -> None:
"""
super().__init__(event_engine, gateway_name)

self.trade_ws_api: BinanceUsdtTradeWebsocketApi = BinanceUsdtTradeWebsocketApi(self)
self.market_ws_api: BinanceUsdtDataWebsocketApi = BinanceUsdtDataWebsocketApi(self)
self.rest_api: BinanceUsdtRestApi = BinanceUsdtRestApi(self)
self.trade_ws_api: BinanceLinearTradeWebsocketApi = BinanceLinearTradeWebsocketApi(self)
self.market_ws_api: BinanceLinearDataWebsocketApi = BinanceLinearDataWebsocketApi(self)
self.rest_api: BinanceLinearRestApi = BinanceLinearRestApi(self)

self.orders: dict[str, OrderData] = {}

Expand Down Expand Up @@ -202,21 +202,21 @@ def get_order(self, orderid: str) -> OrderData:
return self.orders.get(orderid, None)


class BinanceUsdtRestApi(RestClient):
"""The REST API of BinanceUsdtGateway"""
class BinanceLinearRestApi(RestClient):
"""The REST API of BinanceLinearGateway"""

def __init__(self, gateway: BinanceUsdtGateway) -> None:
def __init__(self, gateway: BinanceLinearGateway) -> None:
"""
The init method of the api.
gateway: the parent gateway object for pushing callback data.
"""
super().__init__()

self.gateway: BinanceUsdtGateway = gateway
self.gateway: BinanceLinearGateway = gateway
self.gateway_name: str = gateway.gateway_name

self.trade_ws_api: BinanceUsdtTradeWebsocketApi = self.gateway.trade_ws_api
self.trade_ws_api: BinanceLinearTradeWebsocketApi = self.gateway.trade_ws_api

self.key: str = ""
self.secret: str = ""
Expand Down Expand Up @@ -730,18 +730,18 @@ def query_history(self, req: HistoryRequest) -> list[BarData]:
return history


class BinanceUsdtTradeWebsocketApi(WebsocketClient):
"""The trade websocket API of BinanceUsdtGateway"""
class BinanceLinearTradeWebsocketApi(WebsocketClient):
"""The trade websocket API of BinanceLinearGateway"""

def __init__(self, gateway: BinanceUsdtGateway) -> None:
def __init__(self, gateway: BinanceLinearGateway) -> None:
"""
The init method of the api.
gateway: the parent gateway object for pushing callback data.
"""
super().__init__()

self.gateway: BinanceUsdtGateway = gateway
self.gateway: BinanceLinearGateway = gateway
self.gateway_name: str = gateway.gateway_name

def connect(self, url: str, proxy_host: str, proxy_port: int) -> None:
Expand Down Expand Up @@ -862,18 +862,18 @@ def on_disconnected(self) -> None:
self.gateway.rest_api.start_user_stream()


class BinanceUsdtDataWebsocketApi(WebsocketClient):
"""The data websocket API of BinanceUsdtGateway"""
class BinanceLinearDataWebsocketApi(WebsocketClient):
"""The data websocket API of BinanceLinearGateway"""

def __init__(self, gateway: BinanceUsdtGateway) -> None:
def __init__(self, gateway: BinanceLinearGateway) -> None:
"""
The init method of the api.
gateway: the parent gateway object for pushing callback data.
"""
super().__init__()

self.gateway: BinanceUsdtGateway = gateway
self.gateway: BinanceLinearGateway = gateway
self.gateway_name: str = gateway.gateway_name

self.ticks: dict[str, TickData] = {}
Expand Down Expand Up @@ -1025,3 +1025,9 @@ def generate_datetime(timestamp: float) -> datetime:
dt: datetime = datetime.fromtimestamp(timestamp / 1000)
dt: datetime = dt.replace(tzinfo=UTC_TZ)
return dt


class BinanceUsdtGateway(BinanceLinearGateway):
"""Compatibility interface for the old BinanceUsdtGateway"""

default_name: str = "BINANCE_USDT"

0 comments on commit 1856cbf

Please sign in to comment.