Galts-Gulch / avarice

Multi-Indicator Python3 OKCoin CN & Intl Trading Bot/Infrastructure
Other
91 stars 29 forks source link

Real trade error #17

Open Sim-fo opened 9 years ago

Sim-fo commented 9 years ago

Unfortunately, the third version of the program (v3.2.0) is stable in simulator mode only. During the real trade I get this error:

Future/Task exception was never retrieved
future: Task(<TradeWrapper>)<exception=KeyError('data',)>
Traceback (most recent call last):
  File "/home/ubuntu/workspace/okcoin/WebSocketAPI.py", line 112, in trade
    self.ws.recv())[-1]['data']['order_id']
KeyError: 'data'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 302, in _step
    result = next(coro)
  File "/home/ubuntu/workspace/trader.py", line 46, in TradeWrapper
    el.Trade(trd.LastOrder['order'], CurrPrice, TradeAmount)
  File "/home/ubuntu/workspace/exchangelayer.py", line 60, in Trade
    okwspriv.trade(order, rate, amount)
  File "/home/ubuntu/workspace/okcoin/WebSocketAPI.py", line 121, in trade
    self.ws.recv())[-1]['data']['order_id']
KeyError: 'data'

The trading is stoping after that error, though the bot thinks that transaction are ok, the terminal displays messages about buying and selling, but transactions in the okcoin do not committed.

The error does not appear immediately, usually after two or three successful transactions.

I'm getting the same errors on three different computers with OS Windows 8.1, LinuxMint and with a virtual Ubuntu workspace in the cloud (https://c9.io)

Version 2.0 of the program is stable in all modes and places.

I noticed one more bug. In my settings DiffDown set to -0.02 / 0.02, but transactions are done before that value:

EMA: We are in an Uptrend | Diff: 0.0017436253469297104
StdDev: 0.6119622860161978
BUYING 1.98 btc at 1834.46 cny

Sorry for possible mistakes in English

RealJohnGalt commented 9 years ago

Thank you, looking into this now.

RealJohnGalt commented 9 years ago

I'm still working on the first issue. From genconfig, could you paste your TradeIndicators and sections for any indicator being used?

RealJohnGalt commented 9 years ago

I'm unable to recreate your first issue. Could you try replacing okcoin/WebSocketAPI.py with the following file https://gist.githubusercontent.com/anonymous/59bb36cceca8c6f059c8/raw/f5e94dd11108c6a524eb71895a05888dc16502da/WebSocketAPI.py ?

This will print a new line that starts with "DEBUG" which you could share when the issue occurs to help fix the problem.

Sim-fo commented 9 years ago

If I replace file WebSocketAPI.py, the bot doesn't start, I get this error:

Traceback (most recent call last):
  File "avarice.py", line 5, in <module>
    import avarice
  File "/home/ubuntu/workspace/avarice-master/avarice.py", line 6, in <module>
    import exchangelayer as el
  File "/home/ubuntu/workspace/avarice-master/exchangelayer.py", line 11, in <module>
    from okcoin.WebSocketAPI import OKCoinWSPublic
  File "/home/ubuntu/workspace/avarice-master/okcoin/WebSocketAPI.py", line 116
    print('DEBUG: ' temp)
                   ^
SyntaxError: invalid syntax

As for indicators' parameters, I used EMA and StdDev. The exact parameters I don't remember, but they were approximately like this:

class StdDev:
  VolatilityThresholdOver = True
  Period = 4
  Threshold = 0.6

class EMA:
  IndicatorStrategy = 'CD'
  ShortPeriod = 5
  LongPeriod = 11
  DiffDown = -0.02
  DiffUp = 0.02

class Candles:
  Size = 0.4
RealJohnGalt commented 9 years ago

I apologize for the typo on WebSocketAPI.py. I've fixed it and additionally tested it this time. Here it is: https://gist.github.com/anonymous/78b1c93b5da51149814c . If you could include the "DEBUG" lines around the error, then we can fix the issue.

If you want to trade off Diff (100 * (shortEMA - longEMA) / ((shortEMA + longEMA) / 2)) instead of CD (short and long EMA crosses), then you must change EMA's IndicatorStrategy to "Diff" from "CD". If I misunderstood this issue, please let me know.

Thank you again.

Sim-fo commented 9 years ago

If you want to trade off Diff (100 * (shortEMA - longEMA) / ((shortEMA + longEMA) / 2)) instead of CD (short and long EMA crosses), then you must change EMA's IndicatorStrategy to "Diff" from "CD". If I misunderstood this issue, please let me know.

No, I want to use CD indicator strategy. I mean EMA indicator settings DiffDown and DiffUp.

My EMA settings:

DiffDown = -0.02 
DiffUp = 0.02
SingleTrade = False
TradeVolume = 99

The transaction is executed before these values. For example: This selling is ok because -0.026891961 < -0.02

EMA : We are in an Uptrend | Diff: 0.0158472027668225235
EMA : We are in a Downtrend | Diff: -0.02689196163868669 
SELLING 2.035 btc at 1776.03 cny  

This buying is wrong because 0.00547953065 < 0.02

EMA : We are in a Downtrend | Diff: -0.03117625372650223 
EMA : We are in an Uptrend | Diff: 0.0054795306542315654 
BUYING 2.035 btc at 1776.18 cny  

I set 'SingleTrade = Fasle', because in case with [['StdDev', 'EMA']] when using 'SingleTrade = True' bot sees no change in trend's direction, if it occurred outside the range allowed by StdDev .

By the way, it would be much easier if we could use 'SingleTrade = True' with an indicator of volatility. If 'SingleTrade = Fasle', bot cancels limit orders, made by hand on each new candle. With these settings is virtually impossible to trade together with the bot at the same time, especially when candle's time is short. In case 'SingleTrade = True', manually set limit orders would be cancel only if trend's direction is changed. It is much more convenient.

It would be perfect if the bot could only cancel its own orders, but would never cancel orders made manually, even if the trend is changed.

If you could include the "DEBUG" lines around the error, then we can fix the issue.

Thanks, that's debug text:

Candle: 35 | Price: 1775.89 cny | Time: 01:25:28 | Date: 2015/03/14
EMA : We are in an Uptrend | Diff: 0.0054795306542315654
StdDev: 2.7490008838439883
BUYING 2.035 btc at 1776.0 cny
DEBUG:  [{"channel":"ok_spotcny_trade","data":{"order_id":"408657798","result":"true"}}]
DEBUG:  [{"channel":"ok_spotcny_trade","errorcode":"10010","success":"false"}]
DEBUG:  [{"channel":"ok_spotcny_trade","errorcode":"10010","success":"false"}]
Future/Task exception was never retrieved
future: Task(<TradeWrapper>)<exception=KeyError('data',)>
Traceback (most recent call last):
  File "/home/ubuntu/workspace/okcoin/WebSocketAPI.py", line 117, in trade
    OKCoinWSPrivate.TradeOrderID = json.loads(temp)[-1]['data']['order_id']
KeyError: 'data'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 302, in _step
    result = next(coro)
  File "/home/ubuntu/workspace/trader.py", line 46, in TradeWrapper
el.Trade(trd.LastOrder['order'], CurrPrice, TradeAmount)
  File "/home/ubuntu/workspace/exchangelayer.py", line 60, in Trade
    okwspriv.trade(order, rate, amount)
  File "/home/ubuntu/workspace/okcoin/WebSocketAPI.py", line 127, in trade
    OKCoinWSPrivate.TradeOrderID = json.loads(temp)[-1]['data']['order_id']
KeyError: 'data'
Candle: 36 | Price: 1775.99 cny | Time: 01:25:52 | Date: 2015/03/14
EMA : We are in an Uptrend | Diff: 0.016285817849564142
StdDev: 2.642106167435374
BUYING 0.021 btc at 1776.71 cny
Candle: 37 | Price: 1775.38 cny | Time: 01:26:16 | Date: 2015/03/14
EMA : We are in an Uptrend | Diff: 0.011446582146929
StdDev: 2.5646155139464883
BUYING 0.021 btc at 1775.64 cny

Here is the full logs and setting text, just in case: https://dl.dropboxusercontent.com/u/45855789/DEBUG.rar

RealJohnGalt commented 9 years ago

I can handle the trade issue by catching that exception in TradeWrapper, and having it wait until the next run to finish the trade. Currently it will cancel that trade, then the exception kills that event loop stopping the reissue and all future trades.

I really appreciate your debugging, it looks like this will be fixed quickly :+1:

RealJohnGalt commented 9 years ago

6b14fdc Doesn't break trader when it runs into this issue which is an improvement at least. I'm working on a better way to handle this condition without reverting to additional API hits.

Sim-fo commented 9 years ago

Thank you so much! It seems that everything works. I had little time for test today. I'll do more tests tomorrow.

DiffDown and DiffUp are only used for the "Diff" indicatorstrategy. It seems that you only want to use them as a filter, but this is unnecessary. EMADiff (explained above) would never cross DiffDown in an uptrend, or cross DiffUp in a downtrend. So if you only want to trade when EMADiff is beyond the settings, you would need to set EMA to "Diff"

Oops .. Sorry, my mistake. Thank you for the explanation.

RealJohnGalt commented 9 years ago

Thank you. In case you misunderstood, SingleTrade is still buggy. I'm still working on the fix, since it still currently misses signals with volatility indicators as you pointed out.

RealJohnGalt commented 9 years ago

71a9bd5 Fixes that SingleTrade issue (and others) :+1: . The trader still isn't entirely fixed with that issue you had, but at least it won't completely break now. I'll update this issue when it's entirely fixed.

Sim-fo commented 9 years ago

Sorry, I didn't have a chance to get to you earlier

Errors now occurs much less frequently after last update. But they still appear. Usually that occurs when the trading volumes rise dramatically. The bot does stop trading after that:

Future/Task exception was never retrieved
future: Task(<TradeWrapper>)<exception=SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1767)')>
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 302, in _step
    result = next(coro)
  File "/home/ubuntu/workspace/trader.py", line 37, in TradeWrapper
    elif el.OrderExist():
  File "/home/ubuntu/workspace/exchangelayer.py", line 54, in OrderExist
    if GetFrozen('asset') > 0 or GetFrozen('currency') > 0.003:
  File "/home/ubuntu/workspace/exchangelayer.py", line 48, in GetFrozen
    okwspriv.userinfo())[-1]['data']['info']['funds']['freezed'][gc.API.Asset]
  File "/home/ubuntu/workspace/okcoin/WebSocketAPI.py", line 75, in userinfo
    info = self.ws.recv()
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 747, in recv
    opcode, data = self.recv_data()
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 764, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 777, in recv_data_frame
    frame = self.recv_frame()
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 829, in recv_frame
    frame_buffer.recv_header(self._recv_strict)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 308, in recv_header
    header = recv_fn(2)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 961, in _recv_strict
    bytes = self._recv(shortage)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 939, in _recv
    bytes = self.sock.recv(bufsize)
  File "/usr/lib/python3.4/ssl.py", line 731, in recv
    return self.read(buflen)
  File "/usr/lib/python3.4/ssl.py", line 620, in read
    v = self._sslobj.read(len or 1024)
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1767)
Exception in thread Thread-79:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 1186, in run
    self.function(*self.args, **self.kwargs)
  File "/home/ubuntu/workspace/genutils.py", line 16, in do_every
    worker_func()
  File "avarice.py", line 44, in RunCommon
    trd.TradeFromStrategy()
  File "/home/ubuntu/workspace/trader.py", line 65, in TradeFromStrategy
    TradeAmount = GetTradeAmount('buy', st.Trade_dict['TradeVolume'])
  File "/home/ubuntu/workspace/trader.py", line 20, in GetTradeAmount
    ((volume / 100) * el.GetFree('currency') / el.GetMarketPrice('ask')), 3)
  File "/home/ubuntu/workspace/exchangelayer.py", line 36, in GetFree
    okwspriv.userinfo())[-1]['data']['info']['funds']['free'][gc.API.Currency]
  File "/home/ubuntu/workspace/okcoin/WebSocketAPI.py", line 75, in userinfo
    info = self.ws.recv()
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 747, in recv
    opcode, data = self.recv_data()
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 764, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 777, in recv_data_frame
    frame = self.recv_frame()
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 829, in recv_frame
    frame_buffer.recv_header(self._recv_strict)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 308, in recv_header
    header = recv_fn(2)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 961, in _recv_strict
    bytes = self._recv(shortage)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 939, in _recv
    bytes = self.sock.recv(bufsize)
  File "/usr/lib/python3.4/ssl.py", line 731, in recv
    return self.read(buflen)
  File "/usr/lib/python3.4/ssl.py", line 620, in read
    v = self._sslobj.read(len or 1024)
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1767)

Also appeared such mistakes:

Candle: 58 | Price: 1590.95 cny | Time: 18:27:43 | Date: 2015/03/19
EMA : We are in a Downtrend | Diff: -0.014089212047619582
Exception in thread Thread-115:
Traceback (most recent call last):
  File "C:\Python34\lib\threading.py", line 920, in _bootstrap_inner
    self.run()
  File "C:\Python34\lib\threading.py", line 1186, in run
    self.function(*self.args, **self.kwargs)
  File "C:\avarice-master_19.03\avarice-master\genutils.py", line 16, in do_every
    worker_func()
  File "C:\avarice-master_19.03\avarice-master\avarice.py", line 44, in RunCommon
    trd.TradeFromStrategy()
  File "C:\avarice-master_19.03\avarice-master\trader.py", line 77, in TradeFrom
Strategy
    TradeAmount = GetTradeAmount('sell', st.Trade_dict['TradeVolume'])
  File "C:\avarice-master_19.03\avarice-master\trader.py", line 22, in GetTradeAmount
    ta = gu.RoundIfGreaterThan((volume / 100) * el.GetFree('asset'), 3)
  File "C:\avarice-master_19.03\avarice-master\exchangelayer.py", line 39, in GetFree
    okwspriv.userinfo())[-1]['data']['info']['funds']['free'][gc.API.Asset]
  File "C:\avarice-master_19.03\avarice-master\okcoin\WebSocketAPI.py", line 74,
 in userinfo
    'parameters':{ 'api_key':'" + self.api_key + "', 'sign':'" + sign + "'} }")
  File "C:\Python34\lib\site-packages\websocket\_core.py", line 686, in send
    return self.send_frame(frame)
  File "C:\Python34\lib\site-packages\websocket\_core.py", line 712, in send_frame
    l = self._send(data)
  File "C:\Python34\lib\site-packages\websocket\_core.py", line 923, in _send
    return self.sock.send(data)
  File "C:\Python34\lib\ssl.py", line 679, in send
    v = self._sslobj.write(data)
ConnectionResetError: [WinError 10054] An existing connection was forcibly close
d by the remote host

May be I've not seen this error before. The bot also ceases to trade after that, the error after the first appearance occurs continuously.

There was also such non-critical errors, sales doesn't stop after them:

Exception in thread Thread-32:
Traceback (most recent call last):
  File "C:\Python34\lib\threading.py", line 920, in _bootstrap_inner
    self.run()
  File "C:\Python34\lib\threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python34\lib\concurrent\futures\process.py", line 226, in _queue_mana
gement_worker
    ready = wait([reader] + sentinels)
  File "C:\Python34\lib\multiprocessing\connection.py", line 845, in wait
    ov, err = _winapi.ReadFile(fileno(), 0, True)
OSError: [WinError 0] The operation completed successfully

Thanks in advance

Sim-fo commented 9 years ago

Right now there was a strange error about Ichimoku indicator, but I used EMA:

EMA : We are in an Uptrend | Diff: 0.0037319436128943543
TRADER: Wanted to BUY 0.004 btc at 1601.0 but needed more cny
Candle: 265 | Price: 1601.0 cny | Time: 21:09:25 | Date: 2015/03/19
EMA : We are in a Downtrend | Diff: -0.007654971008661396
# ==============
In this time the price is jumped up sharply. The bot have no time to sell. (maybe it's error's reason?)
===============
Candle: 266 | Price: 1601.8 cny | Time: 21:09:56 | Date: 2015/03/19
EMA : We are in an Uptrend | Diff: 0.0013246754446213942
TRADER: Wanted to BUY 0.004 btc at 1601.88 but needed more cny
Exception in thread Thread-65:
Traceback (most recent call last):
  File "C:\Python34\lib\shelve.py", line 111, in __getitem__
    value = self.cache[key]
KeyError: 'Ichimoku_SenkouSpanBRT_list'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python34\lib\threading.py", line 920, in _bootstrap_inner
    self.run()
  File "C:\Python34\lib\threading.py", line 1186, in run
    self.function(*self.args, **self.kwargs)
  File "C:\avarice-master_19.03\avarice-master\genutils.py", line 16, in do_ever
y
    worker_func()
  File "C:\avarice-master_19.03\avarice-master\avarice.py", line 40, in RunCommo
n
    {executor.submit(getattr(indicators, ind).indicator()): ind for ind in gc.In
dicatorList}
  File "C:\avarice-master_19.03\avarice-master\avarice.py", line 40, in <dictcom
p>
    {executor.submit(getattr(indicators, ind).indicator()): ind for ind in gc.In
dicatorList}
  File "C:\avarice-master_19.03\avarice-master\indicators.py", line 493, in indi
cator
    if len(storage.getlist('Ichimoku_SenkouSpanBRT_list')) >= gc.Ichimoku.Chikou
SpanPeriod:
  File "C:\avarice-master_19.03\avarice-master\storage.py", line 26, in getlist
    temp = db[ln]
  File "C:\Python34\lib\shelve.py", line 114, in __getitem__
    value = Unpickler(f).load()
EOFError: Ran out of input

The bot ceases to trade after that, the error after the first appearance occurs continuously.

RealJohnGalt commented 9 years ago

Thank you for catching these! Those first errors are new and apparently pop up when OKCoin API is under high load (their issue). We now gracefully handle them and attempt a reconnection.

That second is a pickle error (what we use for storing indicator data for better resume). I'm attempting this last commit as a simple workaround while testing on 5 0.05m avarice instances to see if I run into more issues from it. If so, then I'll need to get rid of multiprocessing for the indicators until I can better figure it out.

RealJohnGalt commented 9 years ago

I switched back to a single threaded indicator solution so that issue won't come up. I'm going to do a proper queue system to make storage thread safe.

Sim-fo commented 9 years ago

More errors: windows 8.1

EMA : We are in a Downtrend | Diff: -0.001135149331466369
TRADER: SELLING 0.012 btc at 1615.0 cny
Future/Task exception was never retrieved
future: Task(<TradeWrapper>)<exception=TypeError("Can't convert 'NoneType' objec
t to str implicitly",)>
Traceback (most recent call last):
  File "C:\Python34\lib\asyncio\tasks.py", line 321, in _step
    result = next(coro)
  File "C:\avarice-master_19.03\avarice-master\trader.py", line 38, in TradeWrap
per
    el.CancelLastOrderIfExist()
  File "C:\avarice-master_19.03\avarice-master\exchangelayer.py", line 63, in Ca
ncelLastOrderIfExist
    okwspriv.cancelorder(okwspriv.TradeOrderID)
  File "C:\avarice-master_19.03\avarice-master\okcoin\WebSocketAPI.py", line 93,
 in cancelorder
    + "', 'order_id':'" + order_id + "'} }")
TypeError: Can't convert 'NoneType' object to str implicitly

cloud9

EMA : We are in a Downtrend | Diff: -0.030781047511187015
StdDev: 1.0305244080348561
Future/Task exception was never retrieved
future: Task(<TradeWrapper>)<exception=SSLError(1, '[SSL: BLOCK_CIPHER_PAD_IS_WRONG] block cipher pad is wrong (_ssl.c:1767)')>
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 302, in _step
    result = next(coro)
  File "/home/ubuntu/workspace/trader.py", line 35, in TradeWrapper
    'price'], trd.LastOrder['amount'])
  File "/home/ubuntu/workspace/exchangelayer.py", line 60, in Trade
    okwspriv.trade(order, rate, amount)
  File "/home/ubuntu/workspace/okcoin/WebSocketAPI.py", line 127, in trade
    self.ws.recv())[-1]['data']['order_id']
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 747, in recv
    opcode, data = self.recv_data()
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 764, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 777, in recv_data_frame
    frame = self.recv_frame()
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 829, in recv_frame
    frame_buffer.recv_header(self._recv_strict)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 308, in recv_header
    header = recv_fn(2)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 961, in _recv_strict
    bytes = self._recv(shortage)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 939, in _recv
    bytes = self.sock.recv(bufsize)
  File "/usr/lib/python3.4/ssl.py", line 731, in recv
    return self.read(buflen)
  File "/usr/lib/python3.4/ssl.py", line 620, in read
    v = self._sslobj.read(len or 1024)
ssl.SSLError: [SSL: BLOCK_CIPHER_PAD_IS_WRONG] block cipher pad is wrong (_ssl.c:1767)
Exception in thread Thread-13:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 1186, in run
    self.function(*self.args, **self.kwargs)
  File "/home/ubuntu/workspace/genutils.py", line 16, in do_every
    worker_func()
  File "avarice.py", line 44, in RunCommon
    trd.TradeFromStrategy()
  File "/home/ubuntu/workspace/trader.py", line 77, in TradeFromStrategy
    TradeAmount = GetTradeAmount('sell', st.Trade_dict['TradeVolume'])
  File "/home/ubuntu/workspace/trader.py", line 22, in GetTradeAmount
    ta = gu.RoundIfGreaterThan((volume / 100) * el.GetFree('asset'), 3)
  File "/home/ubuntu/workspace/exchangelayer.py", line 39, in GetFree
    okwspriv.userinfo())[-1]['data']['info']['funds']['free'][gc.API.Asset]
  File "/home/ubuntu/workspace/okcoin/WebSocketAPI.py", line 75, in userinfo
    info = self.ws.recv()
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 747, in recv
    opcode, data = self.recv_data()
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 764, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 777, in recv_data_frame
    frame = self.recv_frame()
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 829, in recv_frame
    frame_buffer.recv_header(self._recv_strict)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 308, in recv_header
    header = recv_fn(2)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 961, in _recv_strict
    bytes = self._recv(shortage)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 939, in _recv
    bytes = self.sock.recv(bufsize)
  File "/usr/lib/python3.4/ssl.py", line 731, in recv
    return self.read(buflen)
  File "/usr/lib/python3.4/ssl.py", line 620, in read
    v = self._sslobj.read(len or 1024)
ssl.SSLError: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:1767)

EMA : We are in a Downtrend | Diff: -0.010556655709385764
StdDev: 0.8340946522360951
Exception in thread Thread-15:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 1186, in run
    self.function(*self.args, **self.kwargs)
  File "/home/ubuntu/workspace/genutils.py", line 16, in do_every
    worker_func()
  File "avarice.py", line 44, in RunCommon
    trd.TradeFromStrategy()
  File "/home/ubuntu/workspace/trader.py", line 77, in TradeFromStrategy
    TradeAmount = GetTradeAmount('sell', st.Trade_dict['TradeVolume'])
  File "/home/ubuntu/workspace/trader.py", line 22, in GetTradeAmount
    ta = gu.RoundIfGreaterThan((volume / 100) * el.GetFree('asset'), 3)
  File "/home/ubuntu/workspace/exchangelayer.py", line 39, in GetFree
    okwspriv.userinfo())[-1]['data']['info']['funds']['free'][gc.API.Asset]
  File "/home/ubuntu/workspace/okcoin/WebSocketAPI.py", line 74, in userinfo
    'parameters':{ 'api_key':'" + self.api_key + "', 'sign':'" + sign + "'} }")
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 686, in send
    return self.send_frame(frame)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 712, in send_frame
    l = self._send(data)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 923, in _send
    return self.sock.send(data)
  File "/usr/lib/python3.4/ssl.py", line 679, in send
    v = self._sslobj.write(data)
ssl.SSLError: [SSL: BAD_WRITE_RETRY] bad write retry (_ssl.c:1636)

EMA : We are in a Downtrend | Diff: -0.01810422904179207
StdDev: 0.9107872052973054
Exception in thread Thread-17:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 1186, in run
    self.function(*self.args, **self.kwargs)
  File "/home/ubuntu/workspace/genutils.py", line 16, in do_every
    worker_func()
  File "avarice.py", line 44, in RunCommon
    trd.TradeFromStrategy()
  File "/home/ubuntu/workspace/trader.py", line 77, in TradeFromStrategy
    TradeAmount = GetTradeAmount('sell', st.Trade_dict['TradeVolume'])
  File "/home/ubuntu/workspace/trader.py", line 22, in GetTradeAmount
    ta = gu.RoundIfGreaterThan((volume / 100) * el.GetFree('asset'), 3)
  File "/home/ubuntu/workspace/exchangelayer.py", line 39, in GetFree
    okwspriv.userinfo())[-1]['data']['info']['funds']['free'][gc.API.Asset]
  File "/home/ubuntu/workspace/okcoin/WebSocketAPI.py", line 74, in userinfo
    'parameters':{ 'api_key':'" + self.api_key + "', 'sign':'" + sign + "'} }")
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 686, in send
    return self.send_frame(frame)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 712, in send_frame
    l = self._send(data)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 923, in _send
    return self.sock.send(data)
  File "/usr/lib/python3.4/ssl.py", line 679, in send
    v = self._sslobj.write(data)
ssl.SSLError: [SSL: BAD_WRITE_RETRY] bad write retry (_ssl.c:1636)

Candle: 1268 | Price: 1612.82 cny | Time: 10:14:29 | Date: 2015/03/20
EMA : We are in a Downtrend | Diff: -1.4097895328879357e-14
StdDev: 0.0
Exception in thread Thread-1270:
Traceback (most recent call last):
  File "/home/ubuntu/workspace/okcoin/WebSocketAPI.py", line 74, in userinfo
    'parameters':{ 'api_key':'" + self.api_key + "', 'sign':'" + sign + "'} }")
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 686, in send
    return self.send_frame(frame)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 712, in send_frame
    l = self._send(data)
  File "/home/ubuntu/.local/lib/python3.4/site-packages/websocket/_core.py", line 923, in _send
    return self.sock.send(data)
  File "/usr/lib/python3.4/ssl.py", line 679, in send
    v = self._sslobj.write(data)
ssl.SSLError: [SSL: BAD_WRITE_RETRY] bad write retry (_ssl.c:1636)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 1186, in run
    self.function(*self.args, **self.kwargs)
  File "/home/ubuntu/workspace/genutils.py", line 16, in do_every
    worker_func()
  File "avarice.py", line 43, in RunCommon
    trd.TradeFromStrategy()
  File "/home/ubuntu/workspace/trader.py", line 77, in TradeFromStrategy
    TradeAmount = GetTradeAmount('sell', st.Trade_dict['TradeVolume'])
  File "/home/ubuntu/workspace/trader.py", line 22, in GetTradeAmount
    ta = gu.RoundIfGreaterThan((volume / 100) * el.GetFree('asset'), 3)
  File "/home/ubuntu/workspace/exchangelayer.py", line 39, in GetFree
    okwspriv.userinfo())[-1]['data']['info']['funds']['free'][gc.API.Asset]
  File "/home/ubuntu/workspace/okcoin/WebSocketAPI.py", line 77, in userinfo
    websocket._exceptions.WebSocketConnectionClosedException, ssl.SSLError,
NameError: name 'ssl' is not defined

more logs from cloud9 https://dl.dropboxusercontent.com/u/45855789/21.03_log_cloud9.txt The bot does stop trading after this errors.

RealJohnGalt commented 9 years ago

74bdb2f7da and bd0a5262d better handle these. I tried playing catchup with okcoin's api issues a little too quickly the other day.

Sim-fo commented 9 years ago

Thank you! During 5 hours (candles size 0.5 ) there haven't occured any errors. Touch wood :)