-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathelonbot_test.py
50 lines (43 loc) · 2.59 KB
/
elonbot_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
import os
import unittest
from unittest.mock import patch
import binance.client
import elonbot
from binance_client import MarginType
from elonbot import ElonBot
class ElonBotTest(unittest.TestCase):
def setUp(self) -> None:
os.environ['BINANCE_KEY'] = 'binance key'
os.environ['BINANCE_SECRET'] = 'binance secret'
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'google app credentials'
os.environ['TWITTER_BEARER_TOKEN'] = 'TWITTER_BEARER_TOKEN'
@patch.object(binance.client.Client, 'get_margin_account',
lambda _: {'userAssets': [{'asset': 'USDT', 'free': 12345}, {'asset': 'DOGE', 'free': 12345}]})
@patch.object(binance.client.Client, 'get_orderbook_ticker', lambda _, symbol: {'askPrice': 0.05})
@patch.object(binance.client.Client, 'get_max_margin_loan', lambda _, asset: {'amount': 12345})
@patch.object(binance.client.Client, 'create_margin_order', lambda _, **params: 'order_id')
@patch.object(elonbot.ElonBot, 'get_image_text', lambda url: '')
def test_trigger(self):
bot = ElonBot('elonmusk', {'doge': 'DOGE', 'btc|bitcoin': 'BTC'}, 'USDT', 1, 2, True,
MarginType.CROSS_MARGIN,
2.0,
process_tweet_text=None,
dry_run=False)
bot.process_tweet(
'{"data": {"text": "DOGE backwards is E GOD"}, "includes": {"media": [{"url": "..."}]}}')
bot.process_tweet(
'{"data": {"text": "Dodge coin is not what we need"}, "includes": {"media": [{"url": "..."}]}}')
@patch.object(binance.client.Client, 'get_isolated_margin_account',
lambda _: {'userAssets': [{'asset': 'USDT', 'free': 12345}, {'asset': 'DOGE', 'free': 12345}]})
@patch.object(binance.client.Client, 'get_orderbook_ticker', lambda _, symbol: {'askPrice': 0.05})
@patch.object(binance.client.Client, 'get_max_margin_loan', lambda _, asset, isolatedSymbol: {'amount': 12345})
@patch.object(binance.client.Client, 'create_margin_order', lambda _, **params: 'order_id')
@patch.object(elonbot.ElonBot, 'get_image_text', lambda url: '')
def test_isolated(self):
bot = ElonBot('elonmusk', {'doge': 'DOGE', 'btc|bitcoin': 'BTC'}, 'USDT', 1, 2, True,
MarginType.ISOLATED_MARGIN,
2.0, process_tweet_text=None, dry_run=False)
bot.process_tweet(
'{"data": {"text": "DOGE backwards is E GOD"}, "includes": {"media": [{"url": "..."}]}}')
bot.process_tweet(
'{"data": {"text": "Dodge coin is not what we need"}, "includes": {"media": [{"url": "..."}]}}')