交易API我们已经开发完成了,目前正在内测,您希望使用API来做什么呢,也可以联系我们来参加内测~
我想用API做两件事,一是快速止损,即发现跌速达到每分钟5元时,立即用market order止损。二是投机,即发现跌速达到每分钟5元时,如果这种情况持续十几分钟,用market order低点买进。
我做这两件事为的是,我预计到不明真相的人民群众太多,参与者没投资经验,总是会对价格趋势过度反应,往往一小时才会回调,所以可以利用过度反应投机。当然这样做是有风险的,遇到真的坏新闻,坏到广大群众应该过度反应的程度,那么我就玩火自焚了,但是小赌怡情嘛。要做这种事肯定不能天天守着,要写dæmon的。你可以许可我参与内测吗?
我考虑过用外国市场,但是觉得还是中国市场守着电脑炒币又喜欢过度反应的用户比较多,针对这些人投机应该在国内做。
我考虑过用BTCChina,但是其API设计得令人吐血,你看一眼我下面的笔记就知道它有多令人吐血了(我编程时用英文思考,所以笔记是英语的,平常我还是用中文思考的)。这个笔记只是在说,发一个合同后,如何检查它是否已经执行(在我的计算中,要用其执行时间,决定是否再发一个更大的合同),没想到检查合同是否执行需要极复杂的逻辑,笔记里有详说。
How to find if an order is executed, on BTCChina
1. If an order is a market order, or it can be executed immediately like
a market order (e.g. buying at a price much beyond the market price), it
will be executed without producing an item in getOrders list. The order
is simply not there, non existance! This can be verified by just go to
order management in the browser and verify market orders ain't there.
You need to look up transactions to find its trace, but there is no way
to look up transactions in BTCChina's API. (Tried "getTransactions" in
the hope that it is there undocumented.) In this case, the order maps to
a single transaction, with an averaged price. I experimented with a
market order of as large as 60BTC, and it is marked a single transaction
. There is no way to find out how the price averaged up.
2. If an order can not be executed immediately, it will obtain an
order ID. This is different from the Transaction ID, because in this
case an order maps to multiple Transactions if needed. I experimented
with a purchase of 53BTC and it is splitted into
multiple transactions.
An order in the order book has an 'amount' and an 'amount_original'. The
latter being the amount of the order, the former means the remain
effective amount to be dealt with, which is the original amount minus
the amount dealt.
So how do you place a limit order and check its result?
1. Obtain a list of all orders (except those dealt like market orders).
2. Place an order.
3. Obtain a new list of all orders, and compare it with the old one.
The newly placed order is often listed a few seconds later, so you have
to try a few times to make sure it is really not there.
4. If the new order is in the new list of orders, find its ID and track
its progress until it either finish or times out.
5. If the new order is not in the new list of orders, keep trying until
it times out, and then assume it is fully dealt like a market order.
There is a risk: if an order is placed, neither listed nor executed for
so long time that the routine times out, then it would be mistakenly
considered as fully dealt. To prevent this:
6. If the new order is not in the new list of orders, and the routine
times out: Update the wallet once to see if the wallet change reflect
the contract being fully dealt. If not, this triggers an alarm and this
market no longer participate trading before human intervention.
But that introduces a new problem: if the wallet is updated 5 minutes
ago, and some others (human using browser for example) deals, before the
routin deals, then it would trigger a false alarm. So far there are no
good ways to deal with this situation. We will have to live with it.