[增强功能] 币安现货接口优化
This commit is contained in:
parent
99ae453c67
commit
68e96dd372
4
Q_n_A.md
4
Q_n_A.md
@ -52,6 +52,10 @@
|
||||
添加
|
||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib
|
||||
source /etc/profile
|
||||
或者:
|
||||
创建一个 /etc/ld.so.conf.d/talib.conf文件,内容:
|
||||
/usr/lib
|
||||
执行sudo ldconfig。
|
||||
|
||||
9、数字货币的增量安装
|
||||
|
||||
|
11
README.md
11
README.md
@ -1,10 +1,13 @@
|
||||
<p align="center">
|
||||
<img src ="https://github.com/msincenselee/vnpy/blob/master/huafu_on_premise.jpg"/>
|
||||
<img src ="blob/master/huafu_on_premise.jpg"/>
|
||||
</p>
|
||||
|
||||
|
||||
# “当你想放弃时,想想你为什么开始。埃隆·马斯克”
|
||||
|
||||
github 链接: https://github.com/msincenselee/vnpy
|
||||
gitee 链接: https://gitee.com/vnpy2/vnpy
|
||||
|
||||
###Fork版本主要改进如下
|
||||
1、 事件引擎,增加运行效率调试功能
|
||||
|
||||
@ -82,6 +85,7 @@
|
||||
- 独立的CTA引擎 cta_crypto,运行数字货币时,替代原版cta_strategy引擎。
|
||||
- 支持bar方式回测/组合回测
|
||||
- 增强期货交易模板
|
||||
- 修正vnpy.gateway.binance现货网关,恢复position
|
||||
|
||||
13、 增加App: cta_stock, 包括:
|
||||
|
||||
@ -95,6 +99,11 @@
|
||||
- 支持可转债日内交易回测,支持动态前复权。
|
||||
- 支持盘前复权信息事件【待更新】
|
||||
|
||||
14、GUI界面增强
|
||||
|
||||
- 交易界面,恢复部分v1版本的快捷功能,如快速平仓
|
||||
- 策略运行界面,增加'保存’,'K线' 按钮,保存策略内部数据,保存切片,查看最新切片K线。
|
||||
- K线切片,支持同一策略内多周期、多品种K线。
|
||||
|
||||
|
||||
大佳
|
||||
|
@ -27,6 +27,7 @@ from vnpy.trader.object import (
|
||||
OrderData,
|
||||
TradeData,
|
||||
AccountData,
|
||||
PositionData,
|
||||
ContractData,
|
||||
BarData,
|
||||
OrderRequest,
|
||||
@ -185,6 +186,9 @@ class BinanceRestApi(RestClient):
|
||||
self.order_count_lock = Lock()
|
||||
self.connect_time = 0
|
||||
|
||||
self.assets = {} # 币资产的合约信息, symbol: contract
|
||||
self.positions = {} # 币持仓信息, symbol: position
|
||||
|
||||
def sign(self, request):
|
||||
"""
|
||||
Generate BINANCE signature.
|
||||
@ -419,16 +423,34 @@ class BinanceRestApi(RestClient):
|
||||
|
||||
def on_query_account(self, data, request):
|
||||
""""""
|
||||
# ==》 account event
|
||||
account = AccountData(
|
||||
accountid=self.gateway_name,
|
||||
balance=0,
|
||||
frozen=0,
|
||||
gateway_name=self.gateway_name
|
||||
)
|
||||
self.gateway.on_account(account)
|
||||
|
||||
# ==> position event
|
||||
for account_data in data["balances"]:
|
||||
account = AccountData(
|
||||
accountid=account_data["asset"],
|
||||
balance=float(account_data["free"]) + float(account_data["locked"]),
|
||||
pos = PositionData(
|
||||
accountid=self.gateway_name,
|
||||
symbol=account_data["asset"],
|
||||
exchange=Exchange.BINANCE,
|
||||
direction=Direction.NET,
|
||||
name='{}现货'.format(account_data["asset"]),
|
||||
volume=float(account_data["free"]) + float(account_data["locked"]),
|
||||
yd_volume=float(account_data["free"]) + float(account_data["locked"]),
|
||||
frozen=float(account_data["locked"]),
|
||||
gateway_name=self.gateway_name
|
||||
)
|
||||
|
||||
if account.balance:
|
||||
self.gateway.on_account(account)
|
||||
#
|
||||
if pos.volume > 0 or (pos.volume == 0 and pos.symbol in self.positions):
|
||||
# 判断是否在本地缓存持仓中
|
||||
self.positions.update({pos.symbol: pos})
|
||||
self.gateway.on_position(copy(pos))
|
||||
|
||||
self.gateway.write_log("账户资金查询成功")
|
||||
|
||||
@ -484,6 +506,22 @@ class BinanceRestApi(RestClient):
|
||||
)
|
||||
self.gateway.on_contract(contract)
|
||||
|
||||
for symbol in [d.get("baseAsset"), d.get("quoteAsset")]:
|
||||
if symbol and symbol not in self.assets:
|
||||
asset_contract = ContractData(
|
||||
symbol=symbol,
|
||||
exchange=Exchange.BINANCE,
|
||||
name="{}现货".format(symbol),
|
||||
pricetick=0.000001,
|
||||
size=1,
|
||||
min_volume=0.00001,
|
||||
product=Product.SPOT,
|
||||
history_data=True,
|
||||
gateway_name=self.gateway_name,
|
||||
)
|
||||
self.assets.update({symbol: asset_contract})
|
||||
self.gateway.on_contract(copy(asset_contract))
|
||||
|
||||
symbol_name_map[contract.symbol] = contract.name
|
||||
|
||||
self.gateway.write_log("合约信息查询成功")
|
||||
|
Loading…
Reference in New Issue
Block a user