forked from kuegi/kuegiBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexchange_test.py
163 lines (115 loc) · 5.04 KB
/
exchange_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from kuegi_bot.exchanges.binance_spot.binance_spot_interface import BinanceSpotInterface
from kuegi_bot.exchanges.bitfinex.bitfinex_interface import BitfinexInterface
from kuegi_bot.exchanges.bitmex.bitmex_interface import BitmexInterface
from kuegi_bot.exchanges.bitstamp.bitstmap_interface import BitstampInterface
from kuegi_bot.exchanges.bybit.bybit_interface import ByBitInterface
from kuegi_bot.exchanges.bybit_linear.bybitlinear_interface import ByBitLinearInterface
from kuegi_bot.exchanges.coinbase.coinbase_interface import CoinbaseInterface
from kuegi_bot.exchanges.huobi.huobi_interface import HuobiInterface
from kuegi_bot.exchanges.kraken.kraken_interface import KrakenInterface
from kuegi_bot.exchanges.phemex.phemex_interface import PhemexInterface
from kuegi_bot.utils import log
from kuegi_bot.utils.dotdict import dotdict
from kuegi_bot.utils.helper import load_settings_from_args
from kuegi_bot.utils.trading_classes import Order
settings= load_settings_from_args()
logger = log.setup_custom_logger("cryptobot",
log_level=settings.LOG_LEVEL,
logToConsole=True,
logToFile= False)
def onTick(fromAccountAction):
logger.info("got Tick "+str(fromAccountAction))
'''bitfinex
settings= dotdict({})
settings.SYMBOL = "tBTCUSD"
client= BitfinexInterface(settings=settings, logger=logger, on_tick_callback=onTick)
#'''
'''kraken
settings= dotdict({})
settings.SYMBOL = "XBT/USD"
client= KrakenInterface(settings=settings, logger=logger, on_tick_callback=onTick)
#'''
'''coinbase
settings= dotdict({})
settings.SYMBOL = "BTC-USD"
client= CoinbaseInterface(settings=settings, logger=logger, on_tick_callback=onTick)
#'''
'''huobi
settings= dotdict({})
settings.SYMBOL = "btcusdt"
client= HuobiInterface(settings=settings, logger=logger, on_tick_callback=onTick)
#'''
'''binance_spot
settings= dotdict({})
settings.SYMBOL = "btcusdt"
client= BinanceSpotInterface(settings=settings, logger=logger, on_tick_callback=onTick)
#'''
'''bitstamp
settings= dotdict({})
settings.SYMBOL = "btcusd"
client= BitstampInterface(settings=settings,logger=logger,on_tick_callback=onTick)
#'''
'''phemex
client= PhemexInterface(settings=settings,logger=logger,on_tick_callback=onTick)
#'''
''' binance_future
from binance_future.exception.binanceapiexception import BinanceApiException
from binance_future.model.candlestickevent import Candlestick
from binance_future import RequestClient, SubscriptionClient
from binance_future.model import CandlestickInterval, OrderSide, OrderType, TimeInForce, SubscribeMessageType
request_client = RequestClient(api_key=apiKey, secret_key=apiSecret)
ws = SubscriptionClient(api_key=apiKey,secret_key=apiSecret)
def callback(data_type: SubscribeMessageType, event: any):
if data_type == SubscribeMessageType.RESPONSE:
print("Event ID: ", event)
elif data_type == SubscribeMessageType.PAYLOAD:
print("Event type: ", event.eventType)
print("Event time: ", event.eventTime)
print(event.__dict__)
if(event.eventType == "kline"):
candle : Candlestick = event.data
print(candle.open,candle.close,candle.high,candle.close,candle.closeTime,candle.startTime,candle.interval)
elif(event.eventType == "ACCOUNT_UPDATE"):
print("Event Type: ", event.eventType)
elif(event.eventType == "ORDER_TRADE_UPDATE"):
print("Event Type: ", event.eventType)
elif(event.eventType == "listenKeyExpired"):
print("Event: ", event.eventType)
print("CAUTION: YOUR LISTEN-KEY HAS BEEN EXPIRED!!!")
else:
print("Unknown Data:")
print()
def error(e: BinanceApiException):
print(e.error_code + e.error_message)
listen_key = request_client.start_user_data_stream()
ws.subscribe_user_data_event(listen_key, callback, error)
request_client.keep_user_data_stream()
bars = request_client.get_candlestick_data(symbol="BTCUSDT", interval=CandlestickInterval.MIN1,
startTime=0, endTime=None, limit=1000)
result = request_client.close_user_data_stream()
'''
#'''
if settings.EXCHANGE == 'bybit':
interface= ByBitInterface(settings= settings,logger= logger,on_tick_callback=onTick)
b= interface.bybit
w= interface.ws
elif settings.EXCHANGE == 'bybit-linear':
interface = ByBitLinearInterface(settings=settings, logger=logger, on_tick_callback=onTick)
b = interface.bybit
w = interface.ws
else:
interface= BitmexInterface(settings=settings,logger=logger,on_tick_callback=onTick)
bars= interface.get_bars(240,0)
def get_wallet_records():
result = []
gotone = True
page = 1
while gotone:
data = b.Wallet.Wallet_getRecords(start_date="2020-01-01", end_date="2021-01-01", limit="50",
page=str(page)).response().result['result']['data']
gotone = len(data) > 0
result = result + data
page = page + 1
return result
#b.Wallet.Wallet_getRecords().response().result['result']['data']
# '''