如何在 ccxt 中为币安期货下市价单?使用 ccxt 进行币安期货交易已经实施
https://github.com/ccxt/ccxt/pull/5907
Run Code Online (Sandbox Code Playgroud)
在这篇文章中,他们建议使用这行代码:
let binance_futures = new ccxt.binance({ options: { defaultMarket: 'futures' } })
Run Code Online (Sandbox Code Playgroud)
上面这行是用 JavaScript 编写的。python 中的等效行会是什么样子?像这样我得到一个错误:
binance_futures = ccxt.binance({ 'option': { defaultMarket: 'futures' } })
NameError: name 'defaultMarket' is not defined
Run Code Online (Sandbox Code Playgroud) 有什么方法可以用来ccxt提取过去给定时间的加密货币的价格吗?
示例:获取当时 binance 上 BTC 的价格2018-01-24 11:20:01
我正在尝试使用 ccxt 从 bitmex 获取 1 分钟的开盘价、最高价、最低价、收盘价和成交量值。一切似乎都很好,但我不知道如何解决这个错误。我知道索引是 7,因为我进入数据帧的 OHLC 列中有 7 个值。我不知道为什么它暗示有 0。非常感谢这让我一整天都头疼:(
# noinspection PyUnresolvedReferences
from datetime import datetime
# noinspection PyUnresolvedReferences
import time
# noinspection PyUnresolvedReferences
import ccxt
# noinspection PyUnresolvedReferences
import numpy as np
import pandas as pd
# noinspection PyUnresolvedReferences
from IPython.display import display, clear_output
OHLCVcolumns = ['date', 'timestamp', 'open', 'high', 'low', 'close', 'volume']
dfOHLCV = pd.DataFrame(index=[], columns=OHLCVcolumns)
bitmex = ccxt.bitmex()
def fetch_current(x):
while True:
if datetime.now().second == x:
break
time.sleep(0.5)
def fetch_mex():
listOHLCV = bitmex.fetch_ohlcv('BTC/USD', …Run Code Online (Sandbox Code Playgroud) 我正在使用 Binance API 来使用 Python 3.6 制作我的交易机器人。和CCXT 库(在这里您可以找到文档)。
他们在其网站上拥有的一项非常有用的功能是能够以当前余额的一定比例下订单:
例如,如果我看着在BTC/USDT加密硬币对,我有50 USDT我的账户,我可以买之间进行选择N的数量BTC或使用100%的帐户的USDT用于购买,因此购买的最高金额BTC,我可以。
我多次阅读文档,但我找不到以任何方式使用 API 执行这些“余额百分比”订单的选项:我唯一能做的就是将 a 传递float给订单函数。这就是我现在下订单的方式:
amount = 0.001
symbol = "BTC/USDT"
def buyorder(amount, symbol): # this makes a market order taking in the amount I defined before, for the pair defined by "symbol"
type = 'market' # or 'limit'
side = 'buy' # or 'sell'
params = {} # …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 okex 交易所版本 5 上使用 ccxt 创建永久限价订单。该 API 成功在现货交易所下订单(限价订单和市价订单),但在永续交易所上失败。这就是我正在尝试的-
exchange_swap = ccxt.okex5({
'apiKey': credentials['okex']['apikey'],
'secret': credentials['okex']['secretkey'],
'password': credentials['okex']['password'],
'options': {
'defaultType': 'swap',
}
})
params = {
"test":True
}
order = exchange_swap.createLimitBuyOrder('XRP-USDT-SWAP',100,0.7)
Run Code Online (Sandbox Code Playgroud)
错误信息-
ccxt.base.errors.BadRequest: okex5 {"code":"1","data":[{"clOrdId":"","ordId":"","sCode":"51000","sMsg":"Parameter posSide error ","tag":""}],"msg":""}
Run Code Online (Sandbox Code Playgroud)
在搜索此错误后,我在他们的文档中发现了这一点-
Error message Http status code Error code
Parameter {0} error. 400 51000
Run Code Online (Sandbox Code Playgroud)
文档链接 - Okex v5
PS - 我可以通过 okex 上的交易仪表板放置此内容,但不能通过 API 放置。我有足够的余额来创建此订单。
整个错误消息是这样的——
Traceback (most recent call last):
File "C:\Users\ishaa\Desktop\trading\Crypto Vibhor\Testing Files\ccxt_test.py", line 70, in
<module>
order = exchange_swap.createLimitBuyOrder('XRP-USDT-SWAP',100,0.7) …Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用ccxt异步库的项目,该项需要释放某个类所使用的所有资源,并显式调用该类的.close()协同程序.我想退出程序ctrl+c并等待异常中的关闭协程.但是,它永远不会被等待.
该应用程序包含的模块harvesters,strategies,traders,broker,和main(加上配置和这样).经纪人启动为交易所指定的策略并执行它们.该策略启动收集必要数据的相关收集器.它还分析数据并在有利可图的机会时产生交易者.主模块为每个交换创建一个代理并运行它.我试图在每个级别捕获异常,但是从未等待过关闭例程.我宁愿在主模块中捕获它以关闭所有交换实例.
收割机
async def harvest(self):
if not self.routes:
self.routes = await self.get_routes()
for route in self.routes:
self.logger.info("Harvesting route {}".format(route))
await asyncio.sleep(self.exchange.rateLimit / 1000)
yield await self.harvest_route(route)
Run Code Online (Sandbox Code Playgroud)
战略
async def execute(self):
async for route_dct in self.harvester.harvest():
self.logger.debug("Route dictionary: {}".format(route_dct))
await self.try_route(route_dct)
Run Code Online (Sandbox Code Playgroud)
经纪人
async def run(self):
for strategy in self.strategies:
self.strategies[strategy] = getattr(
strategies, strategy)(self.share, self.exchange, self.currency)
while True:
try:
await self.execute_strategies()
except KeyboardInterrupt:
await …Run Code Online (Sandbox Code Playgroud) 我正在使用模拟测试一个类对象,即 ccxt.binance。这个模拟对象作为参数传递给我正在测试的函数。最初它是有效的,因为我能够在一定程度上进行测试。但是,当我更改所述对象的值时,该函数不尊重该值并返回 StopIteration 错误。我在模拟设置中遗漏了什么吗?这是代码的示例片段。
这是正在测试的代码
def exchange_history_load(args, ccxt_exchange):
# skip exchange if has no true fetchOHLCV or if exchange has no timeframe specific data
if ((not ccxt_exchange.has['fetchOHLCV']) or (ccxt_exchange.has['fetchOHLCV'] == 'emulated') or
(not ccxt_exchange.timeframes.get(args.timeframe))):
logging.warning(f'Skipping {ccxt_exchange.name}.')
return
# check if exchange is in database. Write to database if not.
exchange_db_data = get_exchange(ccxt_exchange.id)
if not exchange_db_data:
insert_exchange_to_db(ccxt_exchange.id, ccxt_exchange.name)
logging.info(f'Inserted {ccxt_exchange.name} to database.')
exchange_db_data = get_exchange(ccxt_exchange.id)
exchange_db_id = exchange_db_data[0]
logging.info(f'Fetched {ccxt_exchange.name} data.')
# load exchange markets
markets = ccxt_exchange.load_markets()
logging.info(f'Loaded {ccxt_exchange.name} markets.') …Run Code Online (Sandbox Code Playgroud) 我写了一个小脚本,用 ccxt 从 binance 或 bybit 下载 ohlcv 数据。我想从测试网和主网获取蜡烛数据。我查看了 ccxt 代码,两个网络都有网址,但我不知道如何设置该选项。
我想一定有类似的东西。bybitt = ccxt.binance({ 'option': { 'defaultMarket': 'future' }})
有人知道吗?
我正在尝试使用 ccxt ccxt-1.39.93、Python 3 在 Binance Futures 上平仓。
# fetch position
position = binance.fetch_balance()['info']['positions']
pos = [p for p in position if p['symbol'] == "ETHUSDT"][0]
ticker = get_binance_futures(fetch_only=True)
close_position = binance.create_order(symbol=symbol, type="TAKE_PROFIT_MARKET", side="buy", amount=pos['positionAmt'], price=ticker , params={"closePosition": True, "stopPrice": ticker})
Run Code Online (Sandbox Code Playgroud)
我想关闭当前头寸。但是得到了这个错误:
ccxt.base.errors.ExchangeError: binance {"code":-2021,"msg":"Order would immediately trigger."}
Run Code Online (Sandbox Code Playgroud)
是否有一种简单的方法可以以市场或现货价格关闭给定代码的当前头寸?
我尝试通过下面的代码来做到这一点,但出现错误
import ccxt # noqa: E402
import apiConfig
exchange = ccxt.binance({
'apiKey': apiConfig.API_KEY,
'secret': apiConfig.API_SECRET,
'enableRateLimit': True,
})
symbol = 'RVN/USDT'
type = 'limit' # or 'market', other types aren't unified yet
side = 'buy'
amount = 69 # your amount
price = 0.21 # your price
# overrides
params = {
'stopPrice': 0.20, # your stop price
'type': 'stopLimit',
}
order = exchange.create_order(symbol, type, side, amount, price, params)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:ccxt.base.errors.BadRequest:binance {“code”:-1106,“msg”:“不需要时发送参数'stopPrice'。”}
ccxt ×10
python ×8
binance ×5
python-3.x ×2
trading ×2
asynchronous ×1
bitcoin ×1
cryptoapi ×1
rest ×1