提供火币网交易接口API最简封装,提供现货买入、卖出、huobi币安查询账户余额等接口,数字货币,虚拟货币,BTC量化交易框架,自动交易,轻量便携,不用安装,即开即用

Overview

火币网交易接口的最简封装(只管用,不用再关注细节)

提供火币网交易接口的python封装,提供买入、卖出、查询账户余额等接口

接口说明

  • order_value() 进行买入操作,参数为买入的币和买入的金额
    买入返回的详情数据:
    {'单号': '272229546125038', '成交数量': 0.000177, '成交金额': '10.000000', '扣手续费': 3.56240360358, '平均价格': 56497.18}
  • order_target() 进行卖出操作,参数为卖出的币和卖出的金额
    卖出返回的详情数据:
    {'单号': '272229722396768', '成交数量': 0.000177, '成交金额': 9.93279219, '扣手续费': 0.01986558438, '平均价格': 56229.7}
  • get_amount() 获取币的账户余额

最简单的例子,开箱即用 (trade_app.py)

# btc的买入和卖出,以及查询账户余额
from huobi_trade_api import HuobiData
from tools import *

#自己的火币账户的access_key, secret_key (火币每个主账号能创建200个子账号,尽量使用子账号操作,防范风险)
access_key = 'XXXXXXXXXXXXXXXXXXXX'
secret_key = 'XXXXXXXXXXXXXXXXXXXXXXX'
huobi_trade = hb_trade(access_key, secret_key)              #初始化交易类

usdt_balance = huobi_trade.trade.get_balance('usdt')        #查询稳定币usdt的余额

coin_code = 'btc.usdt'                                      #定义交易对 
init_money = 10.00                                          #买入金额(单位:usdt)
buy_json = huobi_trade.order_value(coin_code, init_money)   #用1000USDT 买入btc
#  buy_json 返回字典类型,买入成交回报:
# {'单号':'2722295','成交数量':0.000177,'成交金额':'10.0000','扣手续费':3.562403,'平均价格':56497.18}


amount = huobi_trade.trade.get_amount(coin_code)            #查询btc.usdt交易对的数量,有精度控制
print('当前账户%s数量:' % (coin_code) + str(amount))



sell_json = huobi_trade.order_target(coin_code, amount)     #卖出当前持仓所有btc
# sell_json 返回字典类型,卖出成交回报:
# {'单号':'2722297','成交数量': 0.000177,'成交金额': 9.9327,'扣手续费':0.019865,'平均价格': 56229.7}

最底层的高阶例子 (api_test.py)

from huobi_trade_api import HuobiData
from tools import *

hb = HuobiData(huobi_access_key=access_key, huobi_secret_key=secret_key)
user_info = hb.get_api_user_info()            #账号查询 get_api_user_info
 #    返回的账户信息
 #   [ {'id': 754585, 'type': 'spot', 'subtype': '', 'state': 'working'}, 
 #     {'id': 20605202, 'type': 'otc', 'subtype': '', 'state': 'working'}  ]
user_balance = hb.get_api_user_balance()  # 获取账号余额

# 返回的账号余额信息
#    { "id": 754585,  "type": "spot",    "state": "working",
#    "list": [    {   "currency": "fil",    "type": "trade",   "balance": "0.608150192"     },
#                 {   "currency": "theta",  "type": "trade",  "balance": "0.308798576"     } ]}
amount = hb.get_amount_valuation(currency='CNY')  #获取账户估值 可选BTC,CNY,USD
balance = hb.get_balance('usdt')               #查询币种余额 如btc,usdt,doge
symbols = hb.get_symbols()    #获取交易对精度信息,只获取TradePair内的值
quote-currency price-precision amount-precision value-precision min-order-value sell-market-min-order-amt
hcbtc btc 8 4 8 0.0001
rvnbtc btc 10 2 8 0.0001
insurusdt usdt 4 4 8 5.0000
actbtc btc 10 2 8 0.0001
thetausdt usdt 4 4 8 5.0000
#市价委托下单买
buy_billno = hb.buy_order(code='doge.usdt', amount=10.00)           #用usdt市价买入币doge
#市价委托下单卖
coin_amount = hb.get_balance('doge')                                #查询出doge的余额  
sell_billno = hb.sell_order(code='doge.usdt', amount=coin_amount)   #市价卖出doge币
#查询订单详情 
find_order = hb.find_order('272249503181077')                         #入参是成交单号
#订单详情返回值
{
    "id": 272249503181077,"symbol": "btcusdt","account-id": 754585,
    "client-order-id": "20210508-150246-731828","amount": "10.000000000000000000",
    "price": "0.0","created-at": 1620457349520,"type": "buy-market",
    "field-amount": "0.000173342760868287","field-cash-amount": "9.999999999999956351",
    "field-fees": "0.000000346685521737","finished-at": 1620457349539,
    "source": "spot-api","state": "filled","canceled-at": 0
}
#获取成交明细
order_details = hb.get_order_details('272249503181077')               #入参是成交单号
#成交明细返回值,返回list数组
[
  {
    "fee-currency": "btc", "symbol": "btcusdt", "trade-id": 102415396093,
    "match-id": 127130574857, "source": "spot-api", "role": "taker",
    "order-id": 272249503181077, "price": "57689.17", "created-at": 1620457349541,
    "filled-amount": "0.000173342760868287", "fee-deduct-currency": "", 
    "fee-deduct-state": "done","filled-fees": "0.000000346685521737", 
    "filled-points": "0.0", "id": 267299340030943, "type": "buy-market"
  }
]
#策略委托市价下单
order_detail = hb.set_algo_order(code='ada.usdt', orderValue='10', stopPrice='1.5') 
#策略委托市价下单返回值 {'clientOrderId': '20210510-154908-999949'}
#策略委托撤单
cancel_detail = hb.cancel_algo_order(['20210510-154908-999949'])  
#策略委托撤单返回值 撤销成功的单号在accepted列表里,撤销失败的单号在rejected列表里
#{'accepted': ['20210510-154908-999949'], 'rejected': []}

需安装第三方库

  • requests
  • pandas

巴特量化

  • 数字货币 股市量化工具 行情系统软件开发

  • BTC虚拟货币量化交易策略开发 自动化交易策略运行


加入群聊

A code to match you with the perfect Taylor Swift song for your mood and relationship status.

taylorswift A package for matching your current mood and relationship status to a suitable Taylor Swift song. Requirements: Python 2 or 3, and the num

Megan Mansfield 82 Dec 09, 2022
A method to check whether a Discord user is using the client or not.

Discord Captcha Method This is an example, of a verification trough a check, if the user loads the picture send with the verification-message. This ma

Julien 2 Jan 19, 2022
A template that everyone can use for the start of their discord bot

Python Discord Bot Template This repository is a template that everyone can use for the start of their discord bot. When I first started creating my d

2 Nov 01, 2021
livestream-chat: Overlay para chats de livestreams

livestream-chat Overlay para chats de livestreams. Inicialmente para rodar dentro do browser do obs-studio. TODO: Issues iniciais Suporte a API do You

Eduardo Mendes 10 Dec 16, 2022
A custom rom post bot for Telegram.

Rom Poster Bot A simple Post Bot written in Python using pyTelegramBotAPI to post rom updates to telegram whenever you need. Made by lazy peep for laz

Prajwal 6 Nov 03, 2022
An advanced Filter Bot with nearly unlimitted filters!

Unlimited Filter Bot ㅤㅤㅤㅤㅤㅤㅤ ㅤㅤㅤㅤㅤㅤㅤ An advanced Filter Bot with nearly unlimitted filters! Features Nearly unlimited filters Supports all type of fil

1 Nov 20, 2021
A Telegram bot for Minecraft names

MCTelegramBot About this project This bot allows you to see data about minecraft names in Telegram, it has a few commands such as: /names - Show dropp

Kami 5 May 14, 2022
Lambda-function - Python codes that allow notification of changes made to some services using the AWS Lambda Function

AWS Lambda Function This repository contains python codes that allow notificatio

Elif Apaydın 3 Feb 11, 2022
An API wrapper around Discord API written in Python

Diskord This library is a maintained fork of now archived library, discord.py. A modern and easy to use API wrapper around Discord API written in Pyth

Diskord 36 Aug 22, 2022
Asynchronous wrapper for wttr.in weather forecast.

aiopywttr Asynchronous wrapper for wttr.in weather forecast. Synchronous version here. Installation pip install aiopywttr Example This example prints

Almaz 4 Dec 24, 2022
ShoukoKomiRobot - An anime themed telegram bot that can convert telegram media

ShoukoKomiRobot • 𝕎𝕣𝕚𝕥𝕥𝕖𝕟 𝕀𝕟 Python3 • 𝕃𝕚𝕓𝕣𝕒𝕣𝕪 𝕌𝕤𝕖𝕕 Pyrogram

25 Aug 14, 2022
Unirest in Python: Simplified, lightweight HTTP client library.

Unirest for Python Unirest is a set of lightweight HTTP libraries available in multiple languages, built and maintained by Mashape, who also maintain

Kong 432 Dec 21, 2022
Chorok - High quality Discord music bot

Chorok - High quality Discord music bot Rewrite with dico Config guide

Chorok Opensource project 10 May 03, 2022
Send automated wishes to your contacts at scheduled time through WhatsApp. Written for Raspberry pi.

Whatsapp Automated Wishes Helps to send automated wishes to your contacts in Whatsapp at scheduled time using pywhatkit . Written for Raspberry pi. Wi

Uthayamurthy 2 Dec 13, 2022
Telegram Bot for saving and sharing personal and group notes

EZ Notes Bot (ezNotesBot) Telegram Bot for saving and sharing personal and group notes. Usage Personal notes: reply to any message in PM to save it as

Dash Eclipse 8 Nov 07, 2022
a discord libary that use to make discord bot with low efficiency and bad performance because I don't know how to manage the project

Aircord 🛩️ a discord libary that use to make discord bot with low efficiency and bad performance because I don't know how to manage the project Examp

Aircord 2 Oct 24, 2021
Discord bot built using Python. through this you can get information about the upcoming matches, scoreboard, live score

IPL-bot This is a Discord bot built using Python. through this you can get information about the upcoming matches, scoreboard, live score, and many mo

0 Dec 23, 2021
Policy and data administration, distribution, and real-time updates on top of Open Policy Agent

⚡ OPAL ⚡ Open Policy Administration Layer OPAL is an administration layer for Open Policy Agent (OPA), detecting changes to both policy and policy dat

8 Dec 07, 2022
A simple google translator telegram bot

Translator-Bot A simple google translator telegram bot Please fork this repository don't import code Made with Python3 (C) @FayasNoushad Copyright per

Fayas Noushad 14 Nov 12, 2022
This automation protect against subdomain takeover on AWS env which also send alerts on slack.

AWS_Subdomain_Takeover_Detector Purpose The purpose of this automation is to detect misconfigured Route53 entries which are vulnerable to subdomain ta

Puneet Kumar Maurya 8 May 18, 2022