ctubio / tribeca

Self-hosted crypto trading bot (automated high frequency market making) in node.js, angular, typescript and c++
https://127.0.0.1:3000
Other
95 stars 26 forks source link

NEW OkCoin & GDAX API #26

Closed Camille92 closed 7 years ago

Camille92 commented 7 years ago

Hi everyone,

Recently both Gdax and OkCoin released new API.

For OkCoin, there is now a new error '20103' 'Event type error' blocking the bot.

For Gdax, it still work perfectly but doesn't handle the new margin trading which is on a separate API. Also if you do manually margin trading on your account, the bot would go a bit crazy!

I hope we can soon find a solution to the OkCoin issue!

Cheers, Camille

ctubio commented 7 years ago

+info: https://www.okcoin.com/t-354.html

ctubio commented 7 years ago

Please let me know if you still have issues with OkCoin, as far as i tested the market data and the wallet is working now with the new API.

Camille92 commented 7 years ago

I'm going to have a look!

I'm happy to know you're back :)

ctubio commented 7 years ago

yep thanks'¡ back to lovely Barcelona; Autobots, roll out!

goldobarcelona2

Camille92 commented 7 years ago

Hello Sadly after texting trading on OkCoin again, there are big issues about it:

Orders are sent to the market but not seen in the web console Orders are not cancelled

So in a few seconds all orders are in the order book and tribeca can't do anything.

Well and you don't see anything happening in the console :/

ctubio commented 7 years ago

ok let me move some funds to okcoin and fix the errors, sorry i didnt fully tested before

some floats are now strings in okcoin api, so tribeca doesnt understand some numbers now, fixable i believe'¡

Camille92 commented 7 years ago

Send ltc if you want that to be fast haha. 😆

Thank you about for looking at it!

Camille92 commented 7 years ago

Any idea why it's not working ? Any way I can help ?

ctubio commented 7 years ago

now the app crashes when canceling orders that doesnt exists, will fix soon, during today only happened 3 times to me so i couldnt test much

EDIT: finally was the heartbeat i think

ctubio commented 7 years ago

OkCoin changed the direction of the heartbeat, now is the client who sends the ping and OkCoin answers the pong. Now we send a ping to OkCOin every 7 seconds and if we dont get a pong we print a log msg (maybe would be better to try to reconnect instead [i will do if i see logs of lost pongs]). Hope connection doesnt dies anymore now, but let me know if you still have issues'¡

Camille92 commented 7 years ago

Hey I think I was mistaking earlier today with the problem with OkCoin.

But the issue is a bit different: It shows a negative USD balance. capture d ecran 2017-04-17 a 18 50 06

The problem is that tribeca only send 0.01 btc order on the buy side when that happens. Or doesn't send orders (while it shows some on the medium console)

Also there are some ghost orders appearing in the medium console tab but it doesn't seem to have any influence as those orders don't appear on the market.

i don't know if it's very clear :/ I'm sorry there is nothing about that on the logs

Camille92 commented 7 years ago

It seems to be fixed when apr is off.

I'll let you know if I can get something more detailled, I'm very not sure about what's happening!

Have a nice day :)

ctubio commented 7 years ago

as far as i saw, there is some situation when orders are rejected, instead tribeca thinks that is created succesfully and it end ups having in tribeca ghost orders that doesnt exists in the exchange, that when recounting totals, these makes values go below zero.

I experiencied this while the app was also generating many log lines with error 10016=Insufficient coins balance, but i couldnt figure out the root cause yet (i had not enough balance in one side, but i mean the cause in the code). all canceled/rejected msgs seems correctly parsed at all times, will need to debug deeper.

ctubio commented 7 years ago

one quick and dirty solution could be to cancel all open orders when amount available goes below zero xDD but i would like to find the root couse instead.

im looking now to see if the problem is with New orders or with Working orders, for this i need to know if in open orders UI panel, all values exists in the colum "qty" for all open orders or if instead some orders have "qty" column without any value?

i couldnt reproduce this again yet, but if it happens to you please look for column "qty" and let me know if there are some empty'¡ (i will look for it too meanwhile)

many thanks''¡

Camille92 commented 7 years ago

Hi Carles,

Some updates about the issue, after looking at it today I took some screenshots so it is for sure easier for you to find what you need.

capture d ecran 2017-04-20 a 12 47 13 capture d ecran 2017-04-20 a 12 47 31

As you can see in the screenshot, the two first orders do not exist.

I looked in the historic of orders sent to OkCoin and I found the first one, it has been filled.

capture d ecran 2017-04-20 a 12 51 20

However there is not a single trace of the second order. There is not any order of that size sent at that time (or around that time).

I hope it helps but I can't figure out why is that happening!

Camille92 commented 7 years ago

And here is the list of crash that happened:

(1)
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments: 
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: Invalid date, _f: undefined, _strict: undefined, _locale: [object Object]
Error
    at Function.createFromInputFallback (/tribeca/node_modules/moment/moment.js:320:94)
    at configFromString (/tribeca/node_modules/moment/moment.js:2178:11)
    at configFromInput (/tribeca/node_modules/moment/moment.js:2547:9)
    at prepareConfig (/tribeca/node_modules/moment/moment.js:2530:9)
    at createFromConfig (/tribeca/node_modules/moment/moment.js:2497:40)
    at createLocalOrUTC (/tribeca/node_modules/moment/moment.js:2584:12)
    at createLocal (/tribeca/node_modules/moment/moment.js:2588:12)
    at hooks (/tribeca/node_modules/moment/moment.js:16:25)
    at collection.then.coll (/tribeca/app/server/persister.js:184:325)
    at _fulfilled (/tribeca/node_modules/q/q.js:854:54)

(2)
{"name":"tribeca:active","hostname":"f66a671c93a6","pid":14,"level":30,"msg":"Changed quoting mode to false","time":"2017-04-20T04:46:52.782Z","v":0}
{"name":"main","hostname":"f66a671c93a6","pid":14,"level":50,"err":{"message":"not opened","name":"Error","stack":"Error: not opened\n    at WebSocket.send (/tribeca/node_modules/ws/lib/WebSocket.js:358:18)\n    at Timeout.OkCoinWebsocket.setInterval [as _onTimeout] (/tribeca/app/server/gateways/okcoin.js:81:22)\n    at ontimeout (timers.js:386:14)\n    at tryOnTimeout (timers.js:250:5)\n    at Timer.listOnTimeout (timers.js:214:5)"},"msg":"Unhandled exception!","time":"2017-04-20T04:46:53.293Z","v":0}
/tribeca/node_modules/ws/lib/WebSocket.js:358
      else throw new Error('not opened');
           ^

Error: not opened
    at WebSocket.send (/tribeca/node_modules/ws/lib/WebSocket.js:358:18)
    at OkCoinWebsocket.send (/tribeca/app/server/gateways/okcoin.js:22:22)
    at OkCoinOrderEntryGateway.cancelOrder (/tribeca/app/server/gateways/okcoin.js:168:26)
    at OrderBroker.cancelOrder (/tribeca/app/server/broker.js:116:44)
    at OrderBroker.cancelOpenOrders (/tribeca/app/server/broker.js:323:26)
    at exitingEvent (/tribeca/app/server/main.js:232:25)
    at performExit (/tribeca/app/server/main.js:44:15)
    at process.on.err (/tribeca/app/server/main.js:57:5)
    at emitOne (events.js:96:13)
    at process.emit (events.js:191:7)
error: Forever detected script exited with code: 7
error: Script restart attempt #1
{"name":"main","hostname":"f66a671c93a6","pid":24,"level":30,"msg":"Requiring authentication to web client","time":"2017-04-20T04:46:53.951Z","v":0}
{"name":"main","hostname":"f66a671c93a6","pid":24,"level":30,"msg":"Listening to admins on *: 3000","time":"2017-04-20T04:46:54.002Z","v":0}
{"name":"ewma","hostname":"f66a671c93a6","pid":24,"level":30,"msg":"Unable to compute EMWA value","time":"2017-04-20T04:46:54.126Z","v":0}
{"name":"tribeca:active","hostname":"f66a671c93a6","pid":24,"level":30,"msg":"Starting saved quoting state:  true","time":"2017-04-20T04:46:54.137Z","v":0}
{"name":"tribeca:active","hostname":"f66a671c93a6","pid":24,"level":30,"msg":"Changed quoting mode to true","time":"2017-04-20T04:46:55.722Z","v":0}
{"name":"tribeca:gateway:OkCoinWebsocket","hostname":"f66a671c93a6","pid":24,"level":40,"msg":"Got message on unknown topic { data: { result: 'true' }, channel: 'login' }","time":"2017-04-20T04:46:55.953Z","v":0}
{"name":"tribeca:gateway:OkCoinWebsocket","hostname":"f66a671c93a6","pid":24,"level":40,"msg":"Got message on unknown topic { data: { result: true, channel: 'ok_sub_spotusd_btc_depth_20' },\n  channel: 'addChannel' }","time":"2017-04-20T04:46:55.956Z","v":0}
{"name":"tribeca:gateway:OkCoinWebsocket","hostname":"f66a671c93a6","pid":24,"level":40,"msg":"Got message on unknown topic { data: { result: true, channel: 'ok_sub_spotusd_btc_trades' },\n  channel: 'addChannel' }","time":"2017-04-20T04:46:55.961Z","v":0}
{"name":"positionmanager","hostname":"f66a671c93a6","pid":24,"level":30,"msg":"recalculated target base position: 0.67","time":"2017-04-20T04:47:09.381Z","v":0}
{"name":"positionmanager","hostname":"f66a671c93a6","pid":24,"level":30,"msg":"recalculated target base position: 0.67","time":"2017-04-20T04:47:09.648Z","v":0}
{"name":"tribeca:active","hostname":"f66a671c93a6","pid":24,"level":30,"msg":"Changed quoting mode to false","time":"2017-04-20T04:47:48.878Z","v":0}
{"name":"main","hostname":"f66a671c93a6","pid":24,"level":50,"err":{"message":"not opened","name":"Error","stack":"Error: not opened\n    at WebSocket.send (/tribeca/node_modules/ws/lib/WebSocket.js:358:18)\n    at Timeout.OkCoinWebsocket.setInterval [as _onTimeout] (/tribeca/app/server/gateways/okcoin.js:81:22)\n    at ontimeout (timers.js:386:14)\n    at tryOnTimeout (timers.js:250:5)\n    at Timer.listOnTimeout (timers.js:214:5)"},"msg":"Unhandled exception!","time":"2017-04-20T04:47:50.138Z","v":0}
/tribeca/node_modules/ws/lib/WebSocket.js:358
      else throw new Error('not opened');
ctubio commented 7 years ago

awesome, many thanks for all the info'¡ will try to pinpoint a solution for the crashes/stop trading/negative balances of OkCoin gateway.

ctubio commented 7 years ago

Confirmed: ghost orders in panels are really filled orders in OkCoin. the action of canceling an order works OK usally, but it fails when one order is Completed first in the exxchange while the app tries to cancel it,, then the completed order is instead left as Working Pending Cancel and never canceled/removed because the exchange does not respond to the canceling request since the order was already completed.