Github资源:
https://github.com/BitBotFactory/poloniexlendingbot 自动贷款机
https://github.com/Crypto-toolbox/btfxwss API websocket @python3,官方library
https://github.com/scottjbarr/bitfinex REST API
https://github.com/dawsbot/bitfinex 简单的交易算法,根据trading history画图
https://github.com/nlsdfnbch/bitex 连接主流exch的APIs
https://github.com/websocket-client/websocket-client websocket 客户端
https://github.com/ekulyk/PythonPusherClient 这个应该是PCQ?
注意事项:
1 UTC timezone
2 只能使用error code;error msg仅做参考
3 最多5位有效数字,如1.2345和1234.5
URL,初始化WebSocketConnection.url
wss://api.bitfinex.com/ws/2
表示trading pairs前面加 tBTCUSD, tETHUSD
保证金货币单位前面加 fUSD, fBTC
注意,下面所有的东西都是event,所以写成事件响应类型的框架最好。
当收到msg时候,msg['event']表示event type,可以dispatch给相应的handler
使用Json表示error
Generic Error Codes
10000 : Unknown event
10001 : Unknown pair
Info Messages表示连接状态变化,version很重要,但不知道是干嘛用的。
{
"event": "info",
"version": VERSION
}
其他类型的msg表示event
{
"event":"info",
"code": CODE,
"msg": MSG
}
比如Info Codes,使用codes作为key,文本内容可能改变。
20051 : Stop/Restart Websocket Server (please reconnect)
20060 : Entering in Maintenance mode. Please pause any activity and resume after receiving the info message 20061 (it should take 120 seconds at most).
20061 : Maintenance ended. You can resume normal activity. It is advised to unsubscribe/subscribe again all channels.
Array Length 官方可能改变返回的内容长度,这里来看,version应该就是文档的版本。
Message (JSON array) lengths should never be hardcoded. New fields may be appended at the end of a message without changing version.
Ws的官方测试方法?在WebSocketConnection.send_ping()/_check_pong()中实现。
Ping/Pong
Use ping message to test your connection to the websocket server.
// request
{
"event":"ping",
"cid": 1234
}
// response
{
"event":"pong",
"ts": 1511545528111,
"cid": 1234
}
Configuration 这个意思是说,如果想改config,使用conf event;flags是对应的xor值,按位抑或!比如,小数到string和time>string分别是8,32,则需要传递40。【肯定还有其他flag?】
JSON
{
event: "conf",
flags: FLAGS
}
Subscribe to Channels先发请求,等回应。
// request
{
"event": "subscribe",
"channel": CHANNEL_NAME
}
// response
{
"event": "subscribed",
"channel": CHANNEL_NAME,
"chanId": CHANNEL_ID
}
// response-failure
{
"event": "error",
"msg": ERROR_MSG,
"code": ERROR_CODE
}
如果Server端,5秒钟没有新推送,发事件。
[ CHANNEL_ID, "hb" ]
Snapshot 如果订阅了,返回快照;这个和response什么关系?这个属于业务逻辑?
Upon subscribing to a channel an initial snapshot is sent. Typically, the snapshot will have as its first item, the CHANNEL_ID, its second item will be the CHANNEL_NAME and the third item will be an array of UPDATE_MESSAGEs (each of which is itself an array).
So The array would have 3 levels.
[
CHANNEL_ID,
[
[ UPDATE_MESSAGE ],
...
]
]
上文的意思好像是,在订阅成功时候,收到快照;后面都是对快照的更新。
Update
After receiving the snapshot, you will receive updates upon any change.
Session是什么概念?与channel的关系?
CHANNEL_ID's allow you to keep track of the messages, they are static per session, you will receive both the CHANNEL_NAME and the CHANNEL_ID in the response to a subscription message.
[
CHANNEL_ID,
[ UPDATE_MESSAGE ],
]
CHANNEL_NAME: (string) channel name (book, trades, ticker)
CHANNEL_ID: (int) channel identifier. CHANNEL_ID is a numeric channel identifier that the developer can use to distinguish between updates for each subscribed channel.
Error Codes
10300 : Subscription failed (generic)
10301 : Already subscribed
10302 : Unknown channel
这里的Code是怎么包含在update msg里面的?怎么用?
Unsubscribe to Channels
To stop receiving data from a channel you have to send a "unsubscribe" message.
// request
{
"event": "unsubscribe",
"chanId": CHANNEL_ID
}
// response
{
"event": "unsubscribed",
"status": "OK",
"chanId": CHANNEL_ID
}
// response-failure
{
"event": "error",
"msg": ERROR_MSG,
"code": ERROR_CODE
}
Error Codes
10400 : Subscription failed (generic)
10401 : Not subscribed
Abbreviation Glossary https://docs.bitfinex.com/v2/docs/abbreviations-glossary 所有的缩写
做市策略必须足够快(不一定是足够高频);风险在于buy后,价格降低;或者sell后,价格上涨。
做市一般是小仓位,在震荡市中挣钱(钟摆策略?);统计套利则是大仓位,赌差值回归。
最大的风险是手续费。。。
必须是limit order;通过看交易所ip地址知道服务器地址;
最好的是尝试足够的流动性,足够的震荡性,但是不会一直单向移动;
做市策略必须足够快(不一定是足够高频);风险在于buy后,价格降低;或者sell后,价格上涨。
做市一般是小仓位,在震荡市中挣钱(钟摆策略?);统计套利则是大仓位,赌差值回归。
最大的风险是手续费。。。
必须是limit order;通过看交易所ip地址知道服务器地址;
最好的是尝试足够的流动性,足够的震荡性,但是不会一直单向移动;