[암호화폐] 프로젝트#1 : 업비트 지정가 자동 매수/매도하기[3]

avatar
(Edited)

업비트 지정자 자동 매수/매도 프로그램을 개발 중입니다. 오늘은 세 번째 이야기입니다.

주문 현황 만으로 얼마에 몇 개나 매매가 되었는지 파악하기 위한 자료 구조와 알고리즘을 만들고 있습니다. 일부만 체결이 될 수도 있고, 거래가는 가격대도 다양하게 동시에 지원하려고 하다보니, 구조를 잡는데 시간이 많이 걸리고 있습니다. 기본 안은 나와있으니, 좀 더 시물레이션을 해 보면서 문제점을 찾고 있습니다.

자동 매매 프로그램이 가져야 할 중요한 기능 중의 하나는 프로그램이 죽지 않아야 합니다. 그런데 죽지 않는 프로그램을 만들기가 상당히 어렵습니다. 왜 죽는지 알면 대응을 하지만 예상하지 못한 경우가 항상 생기기 때문이죠.

이런 경우에 가장 쉽게 대응하는 방법이 프로그램이 죽으면 다시 실행시키는 겁니다. 다시 실행시키는 프로그램이 죽으면 어떻게 하냐고요? 다시 실행시키는 프로그램을 다시 실행시키면 됩니다. :)


파이썬에서 특정 프로그램이 동작하지 않으면 다시 실행시키는 방법입니다. 방법은 간단합니다. 파이썬 패키지 중 subprocess에 있는 call이라는 함수를 부르면 됩니다.

import os 
import time 
from subprocess import call

while(1) :
    call("python forever.py")

forever.py에 계속 돌리고 싶은 파일명을 적어 넣으면 됩니다. call 함수가 하는 일은 forever.py가 동작 중이면 가만히 있다가 동작하지 않으면 다시 ()안에 있는 문장을 실행시켜 forever.py를 동작시키는 일을 합니다.


다음으로 필요한 일은 프로그램이 실행되었을 때 이전 상태를 기억하는 것입니다. 이것을 위하여 json 데이터를 파일에 읽고 쓰는 방법이 필요합니다. 이것도 사용 방법은 간단합니다. 저장할 데이터가 변경되는 시점에 save_to_file_json() 함수를 부르면 됩니다. 프로그램이 처음 기동될 때는 load_from_json() 함수를 이용하여 저장되어 있는 데이터를 읽어오면 됩니다.

import json
import os

def save_to_file_json(file_name, data) :
    with open(file_name,'w',encoding="utf-8") as make_file: 
       json.dump(data, make_file, ensure_ascii=False, indent="\t") 

def load_from_json(file_name) :
    with open(file_name,'r',encoding="utf-8") as make_file: 
       data=json.load(make_file) 
    return data

json_data = {"symbol":'SCT', "price":1.0}

file_name = 'test.json'
save_to_file_json(file_name, json_data)
infos = load_from_json(file_name)
print("here")

이것으로 개발을 위한 기본 단계는 마무리가 되었습니다. 매매가 잘 동작할 수 있도록 간단하면서도 효율적으로 동작하는 알고리즘을 개발하는 일만 남았습니다.



0
0
0.000
11 comments
avatar

To listen to the audio version of this article click on the play image.

Brought to you by @tts. If you find it useful please consider upvoting this reply.

0
0
0.000
avatar

한발짝씩 앞으로 나아가시는 모습이 너무 좋아요.ㅎㅎ

0
0
0.000
avatar

잘 동작하는 프로그램을 만들어야할텐데요. 계속 고민만 하고 있습니다.

0
0
0.000
avatar

아마도 제 기억이 맞다면, 제가 스팀잇에 가입한후 제대로된 댓글을 단것이 님의 포스팅이였던 것으로 기억해요!
항상 좋은글과 유용한 정보를 많이 주셨던 기억 때문에 그런지 꼭 이루실 것이라는 기대감이 큽니다.

0
0
0.000
avatar

댓글이 거의 없는 재미없는 글인데도 이렇게 응원해 주시니 감사합니다.

0
0
0.000
avatar

jcar토큰 7월 구독 보팅입니다. 삼복 무더위, 건강하게 이겨나가세요. ^^

0
0
0.000
avatar

Congratulations @tradingideas! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You published a post every day of the week

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Vote for @Steemitboard as a witness to get one more award and increased upvotes!
0
0
0.000
avatar

Hi @tradingideas!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 4.367 which ranks you at #2558 across all Steem accounts.
Your rank has improved 23 places in the last three days (old rank 2581).

In our last Algorithmic Curation Round, consisting of 133 contributions, your post is ranked at #108.

Evaluation of your UA score:
  • Some people are already following you, keep going!
  • The readers like your work!
  • Try to work on user engagement: the more people that interact with you via the comments, the higher your UA score!

Feel free to join our @steem-ua Discord server

0
0
0.000
avatar

Thank you for your continued support towards JJM. For each 1000 JJM you are holding, you can get an additional 1% of upvote. 10,000JJM would give you a 11% daily voting from the 700K SP virus707 account.

0
0
0.000
avatar

이런 걸 더 공부하면 조만간 스몬에서 지지않는 방법까지 만들지도 모른다는 생각이 드네요.ㅎㅎㅎ

0
0
0.000