diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/CoinTrader.pyproj b/CoinTrader.pyproj new file mode 100644 index 0000000..a4733e8 --- /dev/null +++ b/CoinTrader.pyproj @@ -0,0 +1,32 @@ + + + + Debug + 2.0 + {b3dc52bc-017a-4af1-a886-71d83ac4fa61} + + main.py + + . + . + {888888a0-9f3d-457c-b088-3a5042f75d52} + Standard Python launcher + + + True + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets + + + + + + + + + + \ No newline at end of file diff --git a/data_manager.py b/data_manager.py new file mode 100644 index 0000000..4b7d01c --- /dev/null +++ b/data_manager.py @@ -0,0 +1,31 @@ + +class Transaction: + def __init__(self): + self.time = None + self.price = None + self.unit = 0 + self.type = None + + def __init__(self, item): + self.time = item['transaction_date'] + self.price = int(item['price']) + self.unit = float(item['units_traded']) + self.type = item['type'] + + def __str__(self, **kwargs): + return '[{}] {} {}'.format(self.time, self.type, self.price) + + +class DataMgr: + def __init__(self): + self.transactions = {} + + def insert(self, item): + transactions_new = {} + tr = Transaction(item) + if tr.time in self.transactions: + return False + + self.transactions[tr.time] = tr + print(tr) + return True diff --git a/datamgr.py b/datamgr.py deleted file mode 100644 index f2e52a8..0000000 --- a/datamgr.py +++ /dev/null @@ -1,12 +0,0 @@ - -class Tick: - def __init__(self): - self.time = None - self.price = None - - -class DataMgr: - def __init__(self): - self.tick_list = None - - def insert(self, time, price, ask): diff --git a/main.py b/main.py index 7641e01..000bcc4 100644 --- a/main.py +++ b/main.py @@ -1,24 +1,56 @@ from xcoin_api_client import * import sched import time +import data_manager + api_key = "api_connect_key" api_secret = "api_secret_key" api = XCoinAPI(api_key, api_secret) +# public api +# +# /public/ticker +# /public/recent_ticker +# /public/orderbook +# /public/recent_transactions +# +# private api +# +# endpoint => parameters +# /info/current +# /info/account +# /info/balance +# /info/wallet_address + + rgParams = { "order_currency": "xrp", "payment_currency": "KRW" } scheduler = sched.scheduler(time.time, time.sleep) -timer_delay = 0.2 +timer_delay = 0.1 + +def printTicker(result): + print("["+time.strftime("%H:%M:%S")+"]" + " status: " + result["status"] + " last: " + result["data"]["closing_price"]) + +def printTransaction(result): + print("["+time.strftime("%H:%M:%S")+"]" + " status: " + result["status"]) + for item in result['data']: + print('\t[' + item['transaction_date']+']' + item['type'] + ' ' + item['price']); +datamgr = data_manager.DataMgr() def main(arg): + #result = api.xcoinApiCall("/public/ticker/" + rgParams["order_currency"], rgParams) + #if result is not None: + # printTicker(result) + result = api.xcoinApiCall("/public/recent_transactions/" + rgParams["order_currency"], rgParams) if result is not None: - print("["+time.strftime("%H:%M:%S")+"]" + " status: " + result["status"] + " last: " + result["data"]["closing_price"]) + for item in reversed(result['data']): + datamgr.insert(item) scheduler.enter(timer_delay, 1, main, (arg, ))